日期:2014-05-16  浏览次数:20399 次

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

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


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


<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" width="60" height="60" />
<div class="gif-loading-box">
<i class="gif-loading" style="display:none;"></i>
<i class="gif-play"></i>
</div>
</div>


如何写正则表达式,然后如何处理呢
------解决方案--------------------
$html = <<<html
<div class="gif-box">
<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" />
<div class="gif-loading-box">
<i class="gif-loading" style="display:none;"></i>
<i class="gif-play"></i>
</div>
</div>
html;
$regImg = preg_match_all('/<img src=\"(.*?)\" alt=\"hbzy\" width=\"60\" height=\"60\" class=\"alignnone size-full wp-image-2100\" \/>/', $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);