php 替换a和b之间的字符串
发布网友
发布时间:2022-04-06 01:56
我来回答
共2个回答
热心网友
时间:2022-04-06 03:26
$str=<<<EOF
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">做个会搭配的女子</a>
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">美国际劳动节</a>
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">联通融</a>
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">不知不觉才是美</a>
EOF;
$res= preg_replace('/(<a .*>).*(<\/a>)/iU','$1$2',$str);
var_mp($res);
文件的编码注意哦
热心网友
时间:2022-04-06 04:44
可以使用正则表达式。
$str = <<<EOT
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">做个会搭配的女子</a>
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">美国际劳动节</a>
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">联通融</a>
<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void(0);" id="post-user">不知不觉才是美</a>
EOT;
echo preg_replace('#(<a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="javascript:void\(0\);" id="post-user">).*?(</a>)#', '$1替换成这个$2', $str);