首页 >后端开发 >php教程 >求正则表达式完成这个需求,该如何解决

求正则表达式完成这个需求,该如何解决

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-13 11:49:21850浏览

求正则表达式完成这个需求

<br /><img src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg" alt="hbzy" width="60" height="60" class="alignnone size-full wp-image-2100" /><br />


找到文章中这样的图片,替换成

<br /><div class="gif-box"><br /><img src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg!static" _src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg!static" class="alignnone size-full wp-image-2100" tsrc="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg" width="60" height="60" /><br /><div class="gif-loading-box"><br /><i class="gif-loading" style="display:none;"></i><br /><i class="gif-play"></i><br /></div><br /></div><br />


如何写正则表达式,然后如何处理呢
------解决方案--------------------
$html = <<
<br /><img src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg" alt="hbzy" width="60" height="60" class="alignnone size-full wp-image-2100" /><br />





html;
$regImg = preg_match_all('/\"hbzy\"/', $html, $matches) ;
$newSrc = $matches[1][0].'!static"'." _src=\"".$matches[1][0]."!static\" tsrc=\"".$matches[1][0];
$html = str_replace($matches[1][0], $newSrc, $html);
var_dump($html);

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn