2012-04-25 12 views
1

どのようにしてXMLページからコンテンツを取得することができますか? 内容を次のようにウェブスクラップでXMLからコンテンツを取得

<entry> 
    <title>News</title> 
    <link rel="alternate" href="http://www.website.com/detail/2688327:BlogPost:1569917"/> 
    <id>tag:www.website.com,2012-04-25:2688327:BlogPost:1569917</id> 
    <updated>2012-04-25T08:30:00.000Z</updated> 
    <author> 
    <name>Username</name> 
    <uri>http://www.website.com/profile/username</uri> 
    </author> 
     <summary type="html"> 
     Hi this is the latest news 
     </summary> 
</entry> 

<entry> 
    <title>News2</title> 
    <link rel="alternate" href="http://www.website.com/detail/2688327:BlogPost:1569917"/> 
    <id>tag:www.website.com,2012-04-25:2688327:BlogPost:1569917</id> 
    <updated>2012-04-25T08:30:00.000Z</updated> 
    <author> 
    <name>Username2</name> 
    <uri>http://www.website.com/profile/username</uri> 
    </author> 
     <summary type="html"> 
     Hi this is the latest news 
     </summary> 
</entry> 

<entry> 
    <title>News3</title> 
    <link rel="alternate" href="http://www.website.com/detail/2688327:BlogPost:1569917"/> 
    <id>tag:www.website.com,2012-04-25:2688327:BlogPost:1569917</id> 
    <updated>2012-04-25T08:30:00.000Z</updated> 
    <author> 
    <name>Username3</name> 
    <uri>http://www.website.com/profile/username</uri> 
    </author> 
     <summary type="html"> 
     Hi this is the latest news 
     </summary> 
</entry> 

<entry> 
    <title>News4</title> 
    <link rel="alternate" href="http://www.website.com/detail/2688327:BlogPost:1569917"/> 
    <id>tag:www.website.com,2012-04-25:2688327:BlogPost:1569917</id> 
    <updated>2012-04-25T08:30:00.000Z</updated> 
    <author> 
    <name>Username4</name> 
    <uri>http://www.website.com/profile/username</uri> 
    </author> 
     <summary type="html"> 
     Hi this is the latest news 
     </summary> 
</entry> 

は、どのように私は、タイトルの配列、ブログのリンク<link rel="alternate" href="http://www.website.com/detail/2688327:BlogPost:1569917"/>、名前とURI(プロフィールリンク)とPHPを使用して要約のような著者の詳細情報を得ることができますか?

答えて

1

チェックアウトSimpleXMLは、XPathの http://php.net/manual/en/book.simplexml.php

$file = 'url or file name'; 
    $xml = simplexml_load_file('$file'); 
    $list= $xml->xpath("/entry"); // root/entry ... 
    print $list[0]->id; 
    #var_dump($list); 
関連する問題