Home > Backend Development > PHP Tutorial > 求正则表达式完成这个需求

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

WBOY
Release: 2016-06-23 14:01:40
Original
940 people have browsed it

<img src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg" alt="hbzy" width="60"    style="max-width:90%" class="alignnone size-full wp-image-2100" />
Copy after login


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

<div class="gif-box"><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"    style="max-width:90%"  style="max-width:90%" / alt="求正则表达式完成这个需求" ><div class="gif-loading-box"><i class="gif-loading" style="display:none;"></i><i class="gif-play"></i></div></div>
Copy after login


如何写正则表达式,然后如何处理呢


回复讨论(解决方案)

$html = <<<img src="http://www.ke6.com/wp-content/uploads/2014/02/hbzy1.jpg" alt="hbzy" width="60"    style="max-width:90%" class="alignnone size-full wp-image-2100" />
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

http://www.tantengvip.com/2014/02/preg-match-html/
Click here

source:php.cn
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template