Heim >Backend-Entwicklung >PHP-Tutorial >求正则表达式完成这个需求

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 14:01:40975Durchsuche

<img class="alignnone size-full wp-image-2100 lazy"  src="/static/imghwm/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-box"><img  class="alignnone size-full wp-image-2100 lazy"  src="/static/imghwm/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>


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


回复讨论(解决方案)

$html = <<<img class="alignnone size-full wp-image-2100 lazy"  src="/static/imghwm/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%"  />
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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:怎么用正则匹配带多个属性的html标签Nächster Artikel:ecshop 里面的$GLOBALS['smarty']->_var里面的_var是在哪定义的为什么是_var而不是其他?

In Verbindung stehende Artikel

Mehr sehen