2014-02-26 59 views
0

我是新來的PHP簡單的XML文件解析器 我有這樣PHP簡單的XML乘務長

<?xml version='1.0' encoding='UTF-8'?> 
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gContact='http://schemas.google.com/contact/2008' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005'> 
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/> 
    <title type='text'>Aditya Technobd's Contacts</title> 
    <generator version='1.0' uri='http://www.google.com/m8/feeds'>Contacts</generator> 
    <entry> 
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/> 
    <title type='text'>Ashfaq Ali</title> 
    <gd:email rel='http://schemas.google.com/g/2005#other' address='[email protected]' primary='true'/> 
    </entry> 
    <entry> 
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/> 
    <title type='text'>Farhad Hossain</title> 
    <gd:email rel='http://schemas.google.com/g/2005#other' address='[email protected]' primary='true'/> 
    </entry> 
</feed> 

我需要的輸出看起來像這樣

名稱的XML文件:阿什法克阿里 電子郵件:阿什法克@ technobd.com

名稱:法哈德·侯賽因 電子郵件:[email protected]

我嘗試它吹代碼不能˚F IND任何線索

$contacts = file_get_contents("public/temporary/contacts_sample.xml"); 
     $feed = simplexml_load_string($contacts); 
     foreach($feed->entry as $entry){ 
      echo "Name: " .$entry->title; 
      echo "<br>"; 
     } 

任何人可以幫助我,我怎樣才能得到

回答

1

我終於解決了這個問題的電子郵件地址

$contacts = file_get_contents("public/temporary/contacts_sample.xml"); 
     $feed = simplexml_load_string($contacts); 
     foreach($feed->entry as $entry){ 
      echo "Name: " .$entry->title; 
      echo "<br>"; 
      echo "Email: " .$entry->children('gd', TRUE)->email->attributes()->address; 
      echo "<br>"; 
     }