PHP 随机生成空白结果
PHP Getting Random Gives Blank Results
这是 WordPress 插件脚本的一部分。我正在尝试编辑它以获得我自己的自定义标题。 returns 文本下方的代码:
random_phrase
'post_title' =>
行没有从 quotes.txt 文件中随机获取一行。知道为什么这不起作用吗?
function random_phrase ()
{
$quotes = file ("quotes.txt");
$num = rand (0, intval (count ($quotes) / 3)) * 3;
echo $quotes[$num] . "<br>" . $quotes[$num + 1];
}
// and create a post
$wpvt_post = array(
'post_title' => random_phrase,
'post_content' => $post_content,
'post_author' => $item['item']['post_author'],
'post_status' => $item['item']['post_status'],
);
尝试
'post_title' => random_phrase(),
也不应该是 echo
,而是 return
。
请注意,您的随机索引生成会出错。
这是 WordPress 插件脚本的一部分。我正在尝试编辑它以获得我自己的自定义标题。 returns 文本下方的代码:
random_phrase
'post_title' =>
行没有从 quotes.txt 文件中随机获取一行。知道为什么这不起作用吗?
function random_phrase ()
{
$quotes = file ("quotes.txt");
$num = rand (0, intval (count ($quotes) / 3)) * 3;
echo $quotes[$num] . "<br>" . $quotes[$num + 1];
}
// and create a post
$wpvt_post = array(
'post_title' => random_phrase,
'post_content' => $post_content,
'post_author' => $item['item']['post_author'],
'post_status' => $item['item']['post_status'],
);
尝试
'post_title' => random_phrase(),
也不应该是 echo
,而是 return
。
请注意,您的随机索引生成会出错。