我有一個XML文件。這是一個小的版本。使用PHP獲取XML值
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
<title>Liste des ebooks</title>
<updated>2012-03-01T01:23:24Z</updated>
<author>
<name>Drown Del</name>
</author>
<opensearch:totalResults>2338</opensearch:totalResults>
<opensearch:itemsPerPage>100</opensearch:itemsPerPage>
<entry>
<category term="Romans" label="Romans"/>
<category term="Aventures" label="Aventures"/>
</entry>
</feed>
首先,我想知道我們如何調用XML方面類似opensearch:totalResults
。
我需要你的幫助以獲得下面的值與PHP。
<opensearch:totalResults>2338</opensearch:totalResults>
我需要得到2338到一個PHP變量。
謝謝。
謝謝大家的回答。
我可以用以下方法修復它。
$xml = simplexml_load_string($xmltext);
$val = $xml->xpath('opensearch:totalResults');
echo $val[0];
老實說,我不能相信你找不到通過搜索功能,這個問題的答案。幾乎每個DOM示例都演示瞭如何使用'getElementsByTagName' – Gordon 2012-03-01 10:11:14
我嘗試過'simplexml_load_string()'而不是'DOMDocument()'。無論如何,我可以解決我的問題。謝謝你的評論。 – 2012-03-01 10:16:29
http://stackoverflow.com/search?q=xml+colon+php – Gordon 2012-03-01 10:16:39