2013-02-03 41 views
0

HTMLXPATH - 保留空間用的getAttribute

<input type='text' name='title[]' value='Some word and another'> 

PHP

$title = $xpath->query('//input')->item(0); 
echo $title = $title->getAttribute('value') 

結果

一些

我需要

一些字和另一

問題 出於某種原因,一切都第一空間被剝離出來後..

回答

1

請務必裝入它作爲HTML,因此它允許您使用單引號:

$dom = new DOMDocument; 
$dom->loadHTML("<input type='text' name='title[]' value='Some word and another'>"); 

$xpath = new DOMXpath($dom); 

echo $xpath->query('//input')->item(0)->getAttribute('value'); 

在此處查看:http://codepad.viper-7.com/pcs3or