Home >Backend Development >PHP Tutorial >PHP randomly extracts titles from content_PHP tutorial
$temp=$LabelArray['content'];
$temp=preg_replace("%<[^>]+>%",',',$temp);//Prevent letters in the URL from being matched
$temp=make_semiangle($temp);//Half-width conversion
if(preg_match_all("%[[:punct:]]([^[:punct:]]{5,30})[[:punct:]]%u",$temp,$arr)){
$i=rand(0,count($arr[0])-1);
$LabelArray['Title']=$arr[1][$i];
}
//Full-width and half-width rotation
function make_semiangle($str)
{
$arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4 ' => '4',
> 9',> E',
> J',> O',
'P' => 'P', 'Q' => 'Q', 'R' => T',
'U' => 'U', 'V' => Y',
> d',> i',
'n' n',> s',
> x','y' => 'y', 'z' => 'z',
> [',
']' => ']', '〖' => ]',
'‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<',
'》' => '>',
'%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',
':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.',
';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|',
'”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"',
' ' => ' ','$'=>'$','@'=>'@','#'=>'#','^'=>'^','&'=>'&','*'=>'*',
'"'=>'"');
return strtr($str, $arr);
}
echo serialize($LabelArray);
?>