PHP按指定内容随机替换网页内关键词
直接封装的一个函数,三个参数
调用方法为 wzwords(查找词,随机词数组,要被替换的内容);
function wzwords($word,$subs,$htmldb){
$i = -1;
do{
$i = strpos($htmldb, $words, $i+1);
if($i!==false){
$pos[] = $i;
}
}while($i!==false);
for($i=0,$mx=count($pos); $i<$mx; $i++){
$tag = str_repeat('^',$wl-1).$i;
$arr[] = $tag;
$htmldb = substr_replace($htmldb, $tag, $pos[$i], $wl);
}
//die($htmldb);
foreach($arr as $e){
$word = $subs[ mt_rand(0, count($subs)-1) ];
$htmldb = str_replace($e, $words.$word, $htmldb);
}
return $htmldb;
}
出自UZCMS开发者的shikai之手.
aaaaaaaa