1
次のコードは、HTMLファイルやPHPファイルからコメント、改行、および余分なスペースを削除しますが、元のファイルに<<<EOT;
が含まれていると問題が発生します。 <<<EOT;
の前後に改行を追加するために使用する正規表現ルールは$pre6
ですか?文字列の前後に改行を追加する正規表現ですか?
//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