我正在我的服务器上尝试这个新脚本,但我似乎不明白为什么它总是给我带来以下错误:
警告: file_get_contents():文件名不能空在第51行中的/include/classes/spin_Artile.php中
-> $string = file_get_contents($filesrand(1,count($files)) -1);
<?PHP
class Spintax
{
public function process($text)
{
return preg_replace_callback(
'/\{(((?>[^\{\}]+)|(?R))*)\}/x',
array($this, 'replace'),
$text
);
}
public function replace($text)
{
$text = $this->process($text[1]);
$parts = explode('|', $text);
return $parts[array_rand($parts)];
}
}
?>
<?PHP
ob_start();
$files = glob("spintax_articles/*.txt");
$spintax = new Spintax();
$string = file_get_contents($files[rand(1, count($files)) -1]);
echo $spintax->process($string);
$page = ob_get_contents();
ob_end_flush();
$fp = fopen("content.txt","w");
fwrite($fp,$page);
fclose($fp);
?>发布于 2014-07-16 19:39:28
如果有实际匹配的文件,那么您可能会得到一个比最大值大1的随机索引。使用:
$string = file_get_contents($files[rand(1, count($files)-1)]);注意-1的位置。
如果没有文件,您应该使用一个条件来检查。
<?php
$files = glob("spintax_articles/*.txt");
if(!empty($files)) {
$spintax = new Spintax();
$string = file_get_contents($files[mt_rand(1, count($files)-1)]);
$fp = fopen("content.txt", "w");
fwrite($fp, $spintax->process($string));
fclose($fp);
}
?>https://stackoverflow.com/questions/24789164
复制相似问题