Home  >  Article  >  Backend Development  >  Analysis of the working principle of PHP ereg_replace() function_PHP tutorial

Analysis of the working principle of PHP ereg_replace() function_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:30:59917browse

We are learningPHP ereg_replace() function prototype: string ereg_replace (string $pattern, string $replacement, string $string)

string eregi_replace (string $pattern, string $replacement, string $string)

PHP ereg_replace() function c, and replace the matched result with $replacement. When $pattern contains pattern units (or sub-patterns), positions in the form of "1" or "$1" in $replacement will be replaced by the content matched by these sub-patterns. And "" or "$0" refers to the content of the entire matching string. It should be noted that the backslash is used as an escape character in double quotes, so you must use "

http://www.bkjia.com/PHPjc/446249.html

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php   </span></span></li><li><span>$</span><span class="attribute">lines</span><span> = </span><span class="attribute-value">file</span><span>('source.php'); //将文件读入数组中  </span></li><li class="alt"><span>for($</span><span class="attribute">i</span><span>=</span><span class="attribute-value">0</span><span>; $i</span><span class="tag"><</span><span class="tag-name">count</span><span>($lines); $i++)  </span></li><li><span>{  </span></li><li class="alt"><span>//将行末以&ldquo;\&rdquo;或&ldquo;#&rdquo;开头的注释去掉  </span></li><li><span>$lines[$i] = eregi_replace("(//|#).*$", "", $lines[$i]);   </span></li><li class="alt"><span>//将行末的空白消除  </span></li><li><span>$lines[$i] = eregi_replace("[ nrtvf]*$", "rn", $lines[$i]);   </span></li><li class="alt"><span>}  </span></li><li><span>//整理后输出到页面  </span></li><li class="alt"><span>echo htmlspecialchars(join("",$lines));  </span></li><li><span class="tag">?></span><span> </span></span></li></ol>
www.bkjia.com

true
http: //www.bkjia.com/PHPjc/446249.html

TechArticleWe are learning the PHP ereg_replace() function prototype: string ereg_replace (string $pattern, string $replacement, string $string ) string eregi_replace (string $pattern, string $replaceme...
Statement:
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