21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
header("Content-Type:text/html;charset=utf-8");
$subject="世界,您好!示例页面safdasfdasfdsafaf0808080势";
$pattern='/[示例页面42424242432def42242342示例页面dsadfa]/';
preg_match($pattern,$subject,$matches);
echo $matches[0];
?>
$linktitle=$wpdb->get_results("SELECT post_title FROM $wpdb->posts WHERE post_status = 'publish'");
// //遍历KEY
$i=0;
while($i<38){
$pattern[$i]='/'.$linktitle[$i]->post_title.'/';
$replace[$i]='this is replace result';
$i++;
}
$content=preg_replace($pattern, $replace, $content)
return $content;
//首先调出数据库中的title
$linktitle=$wpdb->get_results("SELECT post_title FROM $wpdb->posts WHERE post_status = 'publish'");
$nums=rand(1,38);
$post_title=$linktitle[$nums]->post_title;//里面有38个值
if ($post_title){
//如果这38个值里有任意一个在文章中出现,则执行以下函数操作
$replace = array(
$post_title => '<a href="http://host-7:8888/wiki/'.$post_title.'" >'.$post_title.'</a>',
);
$text = str_replace(array_keys($replace), $replace, $text);}
return $text;
$subject="世界,您好!示例页面safdasfdasfdsafaf0808080势";
$pattern='/[示例页面424世界,您好24242432de势f42242342示例页面dsadfa]/';
preg_match($pattern,$subject,$matches);
if (preg_match){
echo '成功'.'$matches[0]'.'$matches[1]','$matches[2]'
}
//$matches[0]应该输出示例页面,$matches[1]应该输出世界,您好,$matches[2]输出势
$subject="世界,您好!示例页面safdasfdasfdsafaf0808080势";
$pattern='/[示例页面42424242432def42242342示例页面dsadfa]/';
preg_match($pattern,$subject,$matches);
if (preg_match){
echo '成功';
}
$subject = "世界,您好!示例页面safdasfdasfdsafaf0808080势";
$pattern = '/示例页面.+/';
if(preg_match($pattern, $subject, $matches)) {
echo ,$matches[0];
}
$subject = "世界,您好!示例页面safdasfdasfdsafaf0808080势";
$pattern = '/示例页面/';
if(preg_match($pattern, $subject)) echo '包含';