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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:49:21
Original
868 people have browsed it

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

<br /><img class="alignnone size-full wp-image-2100 lazy"  src="/static/imghw/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 />
Copy after login


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

<br /><div class="gif-box"><br /><img  class="alignnone size-full wp-image-2100 lazy"  src="/static/imghw/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 />
Copy after login


如何写正则表达式,然后如何处理呢
------解决方案--------------------
$html = <<
<br /><img class="alignnone size-full wp-image-2100 lazy" src="/static/imghw/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);
Copy after login

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template