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

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

WBOY
WBOYOriginal
2016-06-23 14:01:40937browse

<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" />


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

<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>


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


回复讨论(解决方案)

$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);

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

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:怎么用正则匹配带多个属性的html标签Next article:ecshop 里面的$GLOBALS['smarty']->_var里面的_var是在哪定义的为什么是_var而不是其他?

Related articles

See more