我正在使用XPath從我的DomDocument中獲取一些段落。 這工作正常,並返回我所需的數據。如何從DomDocument :: saveHTML中刪除換行符
的問題是,這樣做的時候:
foreach ($paragraph->childNodes as $child) {
$node .= $paragraph->ownerDocument->saveHTML($child);
}
如果有一個初始換行,這將是keept,我想擺脫所有的換行符的。
我tryed:
$node = trim($node); // Does not work
然後:
$breaks = array("\r\n", "\n", "\r");
$node = str_replace($breaks, " ", $node); // Doesn't work
我也tryed:
$paragraph->ownerDocument->formatOutput = false;
$paragraph->ownerDocument->preserveWhiteSpace = false;
沒有工作。
關於如何擺脫這些換行符的任何想法?
預先感謝您。
編輯
這裏是$節點輸入的例子:
<b>Keywords: </b>marine fungus; sediment; anthranilic acid; <i>Penicillium paneum</i>; cytotoxicity
顯然,問題的性質是
這是什麼特殊字符?
謝謝你的回答,但不,結果是一樣的 –
我編輯我的答案可能會幫助你。 –
不,切入者不工作,對不起。 –