이와 비슷한 것이 있습니까?
<?php
$html=<<<SOMECONT
<p>some text</p>
<p>some other random
text with \n at fixed width
and thats great</p>
SOMECONT;
$narr=array_filter(explode(PHP_EOL,$html),'strlen');
echo implode('',$narr);
출력 :
<p>some text</p><p>some other randomtext with
at fixed widthand thats great</p>
편집 :
대안은 더 "더러운"수 있지만 작동 할 수 있음. Afterall, htmltags 사이의 \ n을 모두 제거하면 원본 파일의 압축 된 문자열에서 빈 줄을 제거하는 것처럼 간단 할 수 있습니다.
$split = explode(PHP_EOL,$data);
$data= "";
for($i = 0; $i < count($split); $i++){
$line = $split[$i];
else if(strlen($line) > 0) $data .= $split[$i]."\n"; // filter
}
'
'태그 내부에 있지만 그 하위 태그의 바깥 쪽을 의미합니다. – techfoobar외부의 바깥 쪽. good notgood good –
Lego
DOM 파서를 사용하고 공백 만있는 모든 하위 태그를 제거하십시오. DOMDocument 문서를 이미 보았습니까? –