Home > Backend Development > PHP Tutorial > 一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家

一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:54:04
Original
853 people have browsed it

$text1 = 
'

123345




  •     一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家


  •     一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家


  •     一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家


  •     一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家


';

$test2 = '一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家 $pattern = '/一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家 echo preg_replace($pattern, $test2, $text1);

我用了 $pattern = '/一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家

回复讨论(解决方案)

$pattern = '/<img  src="/static/imghw/default1.png"  data-src="/','src="  class="lazy"  ;</pre alt="一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家" > </p> <p class="sougouAnswer">  <pre class='brush:php;toolbar:false;'>$pattern = '#<img  src="/static/imghw/default1.png"  data-src="/','src="  class="lazy"  ;</pre alt="一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家" > </p> <p class="sougouAnswer">  <pre class='brush:php;toolbar:false;'>str_replace(',',$text1);
Copy after login

str_replace('src="/','src="http://www.qq.com/',$text1);
Copy after login
Copy after login


用文本替换效率肯定没正则高吧?

字符串替换要比正则至少快10倍


str_replace('src="/','src="http://www.qq.com/',$text1);
Copy after login
Copy after login


用文本替换效率肯定没正则高吧?
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template