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>//将行末以“\”或“#”开头的注释去掉 </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>