【发布时间】:2014-07-16 19:31:09
【问题描述】:
我正在我的服务器上尝试这个新脚本,但我似乎无法弄清楚为什么它总是给我以下错误:
警告:file_get_contents():第 51 行 /includes/classes/spin_article.php 中的文件名不能为空
这一行给出了错误 --> $string = file_get_contents($files[rand(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);
?>
【问题讨论】:
-
继续
print_r($files),您会在 glob 中找到一个不是文件的值。 -
$files[rand(1, count($files)) -1]显然没有任何价值。在尝试使用它们之前,您需要确保4files包含您期望的值。 -
我的猜测是没有与
glob匹配的文件。 -
还有,不应该是
$files[mt_rand(1, count($files)-1)]吗?