2012-04-02 37 views
-5

這是我的xml文件,我不知道如何從xml文件中使用php檢索值,如何從xml文件檢索信息。如果您知道請幫助我。如何從xml文件中檢索日期

my xml file: 
    see:http://en.wikipedia.org/w/api.php? format=xml&action=query&titles=vikram&prop=revisions&rvprop=content 


    <api> 
    <query> 
    <normalized> 
    <n from="vikram" to="Vikram"/> 
    </normalized> 
    <pages> 
    <page pageid="1034501" ns="0" title="Vikram"> 
    <revisions> 
    <rev xml:space="preserve"> 
    '''Vikram''' may refer to: *[[Vikram (name)]], a male name in the Hindu 
    community *[[Vikramāditya]], a legendary king of India **Vikram, a character 
    in ''[[Baital Pachisi]]'', identified with Vikramāditya **[[Vikram Samvat]] 
    (Vikram's Era, "V.S." or "B.S"), a popularly used calendar in India and the 
    official calendar of Nepal, established by Vikramaditya *[[Vikram Pandit]], 
    CitiGroup CEO *[[Vikram (actor)]], Vikram Kennedy, a Tamil-language Indian 
film actor *[[Vikram Sarabhai]], an Indian scientist *[[Vikram 
(film)|''Vikram'' (film)]], a 1986 Tamil-language Indian film *[[Vikram (1986 
Telugu film)|''Vikram'' (1986 Telugu film)]], a 1986 Telugu-language Indian 
film *[[Vikram Seth]], a bestselling author of Indian origin ;See also: * 
{{lookfrom|Vikram}} *{{intitle|Vikram}} {{disambig}} 
</rev> 
</revisions> 
</page> 
</pages> 
</query> 
</api> 
+2

有一大堆,你可以使用PHP的XML API的。試試[SimpleXML](http://www.php.net/manual/en/simplexml.examples-basic.php)。 – spencercw 2012-04-02 19:19:12

+0

我不明白請給我示例代碼 – SANSCLAW 2012-04-02 19:31:49

+4

我鏈接的頁面上有示例代碼。我們不是在這裏把代碼餵給你。 – spencercw 2012-04-02 19:34:53

回答

0

可以使用xml_parse_into_struct()函數的一個簡單的解析XML。

<?php 
$simple = "<para><note>simple note</note></para>"; 
$p = xml_parser_create(); 
xml_parse_into_struct($p, $simple, $vals, $index); 
xml_parser_free($p); 
echo "Index array\n"; 
print_r($index); 
echo "\nVals array\n"; 
print_r($vals); 
?> 

source

0

您可以使用PHP的本地DomDocumentSimpleXML

+0

可以給我代碼。 – SANSCLAW 2012-04-02 19:27:54

+0

@ user1308746:這不是讓人們爲你編寫代碼的網站。請看看benedict_w給你的資源,並親自嘗試一下。那麼如果你對你嘗試過的東西有疑問和問題。讓我們知道 – bretterer 2012-04-02 19:38:50