$kw=explode("\n",file_get_contents("keyword.txt"));
shuffle($kw);
keyword.txt只是行中的关键字,例如:
keyword1
keyword2
keyword3
keyword4
keyword5
keyword6
keyword7
keyword8
keyword9
答案 0 :(得分:3)
从该文件中选择随机关键字:
<?php
//$keywords = file('keyword.txt'); OR
$keywords = explode("\n", file_get_contents('keyword.txt'));
echo $keywords[ array_rand($keywords) ];
?>
答案 1 :(得分:0)
我不确定我是否正确理解了这个问题,但如果您想用每行随机关键字替换当前的关键字选择,则需要更改:
$kwd=$kw[$i];
有类似的东西:
$kwds = explode(" ", $kw[$i]); // although I would use foreach to loop through the lines array...
$kwd = reset(shuffle($kwds)); // shuffle the keywords in that line and pick the first one