Home >Backend Development >PHP Tutorial >求正则表达式完成这个需求,该如何解决

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:49:21872browse

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

<br /><img class="alignnone size-full wp-image-2100 lazy"  src="/static/imghwm/default1.png"  data-src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg"   alt="hbzy"    style="max-width:90%"  style="max-width:90%"  /><br />


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

<br /><div class="gif-box"><br /><img  class="alignnone size-full wp-image-2100 lazy"  src="/static/imghwm/default1.png"  data-src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg!static"   _  t    style="max-width:90%"  style="max-width:90%" / alt="求正则表达式完成这个需求,该如何解决" ><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 class="alignnone size-full wp-image-2100 lazy" src="/static/imghwm/default1.png" data-src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg" alt="hbzy" style="max-width:90%" style="max-width:90%" /><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);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP数组处理函数统观Next article:抉择什么PHP框架