$kw=explode("'n",file_get_contents("keyword.txt"));
shuffle($kw);
关键字.txt只是行中的关键字,例如:
keyword1
keyword2
keyword3
keyword4
keyword5
keyword6
keyword7
keyword8
keyword9
要从该文件中选择随机关键字:
<?php
//$keywords = file('keyword.txt'); OR
$keywords = explode("'n", file_get_contents('keyword.txt'));
echo $keywords[ array_rand($keywords) ];
?>
我不确定我是否正确理解了这个问题,但是如果您想将当前的关键字选择替换为每行的随机关键字,则需要更改:
$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