This code can randomly insert ASCII characters into an article; the frontend can then hide these ASCII characters. This approach ensures that the user experience remains unaffected while simultaneously misleading Baidu's web crawler, thereby achieving a pseudo-original content effect.
I downloaded this from several novel websites – it's really handy!
PHP code:
function randAscii($string){
if(empty($string)){
return false;
}
//【随机插入字符串】
preg_match_all("/./u", $string, $arr);
$arrNew = array(1,10);
$str = '';
$inHtmlTag = false;
foreach ($arr[0] as $k=>$v){
if ($v == '<') {
$inHtmlTag = true;
} else if ($v == '>') {
$inHtmlTag = false;
}
if ($inHtmlTag) {
$str.= $v;
} else {
if($k == 0){
$str.= $v.'';
}else{
$key = array_rand($arrNew,1);
$rand = $arrNew[$key];
$shuzi = mt_rand(800, 810);
$str.= ($rand % 10) == 0 ? $v."<i>".$shuzi.";</i>": $v;
}
}
}
return $str;
}CSScode
i {
display:none;
}