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

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

WBOY
Release: 2016-06-23 13:54:04
Original
812 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="\//i';</pre alt="一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家" > </p> <p class="sougouAnswer">  <pre class="sycode" name="code">$pattern = '#<img  src="/#i';</pre alt="一段PHP的preg_replace正则替换代码求优化更好的。谢谢大家" > </p> <p class="sougouAnswer">  <div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="sycode" name="code">str_replace('src="/','src="http://www.qq.com/',$text1);
Copy after login
Copy after login
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:
source:php.cn
Previous article:codeigniter整合xheditor之后,xheditor上图片问题 Next article:phpmywind上传图片到服务器 在哪里修改上传服务器的路径
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
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template