1
以下代碼從HTML和PHP文件中刪除註釋,換行符和額外空間,但是我遇到的問題是原始文件中有<<<EOT;
。我會用之前和之後的<<<EOT;
來使用什麼樣的正則表達式規則?正則表達式在字符串之前和之後添加換行符?
//a bit messy, but this is the core of the program. removes whitespaces, line breaks, and comments. sometimes makes EOT error.
$pre1 = preg_replace('#<!--[^\[<>].*?(?<!!)-->#s', '', preg_replace('~>\s+<~', '><', trim(preg_replace('/\s\s+/', ' ', php_strip_whitespace(stripslashes(htmlspecialchars($uploadfile)))))));
$pre2 = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $pre1);
$pre3 = str_replace(array("\r\n", "\r"), "\n", $pre2);
$pre4 = explode("\r\n", $pre3);
$pre5 = array();
foreach ($pre4 as $i => $line) {
if(!empty($line))
$pre5[] = trim($line);
}
$pre6 = implode($pre5);
echo $pre6;
謝謝,讓我在正確的方向。 – ionFish 2012-02-18 17:42:38