2011-02-06 77 views
0

我灣到這行代碼插入:插入屬性

xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" 

到這行代碼:

<html xmlns="http://www.w3.org/1999/xhtml"> 

所以輸出是這樣的:

<html xmlns="http://www.w3.org/1999/xhtml" 
xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" > 

我使用這個:Simple DOM Parser

時,使用此:

$html->find('html', 0)->outertext = '<html xmlns="http://www.w3.org/1999/xhtml" 
xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" > '; 

整個HTML文件將會丟失,將上面的代碼來代替。它獲取了HTML的所有文字。 但我只是想改變HTML代碼的行。

+0

內容丟失。 – Kissaki 2011-02-06 09:18:59

+0

您的lib文檔在這裏:http://simplehtmldom.sourceforge.net/manual.htm#section_access我不知道它可以添加命名空間的屬性;其實我不這麼認爲。屬性被訪問爲對象屬性,因此僅限於屬性名稱,而PHP不允許在那裏使用`:`AFAIK。你有沒有考慮不使用lib(爲此)?這是一個選擇嗎? – Kissaki 2011-02-06 09:22:59

回答

1

你可以做到這一點,使用簡單DOM解析器:因你而改變了`outertext`這(可能)包括DOM對象的內容以及

$content = $html->find('html', 0); 
$content->outertext = '<html xmlns="http://www.w3.org/1999/xhtml" 
xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>">'.$content->innertext().'</html>';