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