<a href="/post-develop-1223151-1.shtml" title="" target="_blank">2月26日领秀娱乐管理公司顺利签约北京酒吧</a>请问如何使用:preg_replace 将title=""的内容替换为标题?进阶:<a href="/post-develop-1223151-1.shtml" title="内有N张图片" target="_blank">2月26日领秀娱乐管理公司顺利签约北京酒吧[图]</a>请问如何使用:preg_replace 将title=""的内容替换为标题,若遇到title="内有N张图片" 这种,自动将title="" 替换为 title="[图片]+标题"
echo preg_replace('/title=\"内有N张图片\"/i','',$str);
}
<a href="/post-develop-1223151-1.shtml" title="内有N张图片" target="_blank">bbb</a>
……实现后的效果:<a href="/post-develop-1223151-1.shtml" title="abc" target="_blank">abc</a>
<a href="/post-develop-1223151-1.shtml" title="[图片]bbb" target="_blank">bbb</a>
<a href="/post-develop-1223151-1.shtml" title="" target="_blank">abc</a>
<a href="/post-develop-1223151-1.shtml" title="内有N张图片" target="_blank">bbb</a>
html;
$s= preg_replace('/(<a[^>]+title=")("[^>]+>)([^<]+)/is','$1$3$2$3',$s);
echo preg_replace('/(<a[^>]+title=")内有N张图片("[^>]+>)([^<]+)/is','$1[图片]$3$2$3',$s);
<a href="/post-develop-1223151-1.shtml" title="" target="_blank">abc</a>
<a href="/post-develop-1223151-1.shtml" title="内有N张图片" target="_blank">bbb</a>
html;echo preg_replace('#(?<=title=")(.*?)(".*>(.+)</a)#ie', '("$1"?"[图片]":"")."$3$2"', $s);
<a href="/post-develop-1223151-1.shtml" title="abc" target="_blank">abc</a>
<a href="/post-develop-1223151-1.shtml" title="[图片]bbb" target="_blank">bbb</a>