1 | <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%" />
|
로그인 후 복사
找到文章中这样的图片,替换成
1 | <div class = "gif-box" ><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= "求正则表达式完成这个需求" ><div class = "gif-loading-box" ><i class = "gif-loading" style= "display:none;" ></i><i class = "gif-play" ></i></div></div>
|
로그인 후 복사
如何写正则表达式,然后如何处理呢
回复讨论(解决方案)
1 | $html = <<<html<div class = "gif-box" ><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%" /><div class = "gif-loading-box" ><i class = "gif-loading" style= "display:none;" ></i><i class = "gif-play" ></i></div></html<div>
|
html;$regImg = preg_match_all('/
\")
/', $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);
로그인 후 복사