2012-01-10 19 views
0

我有這個功能使用twitter的搜索API正在檢索推特實體圖片的網址PHP

我想獲取推文的顯示圖像。 的XML顯示爲這樣:

<link type="image/png" href="http://a1.twimg.com/profile_images/1625108559/meltaurus_normal.jpg" rel="image" /> 

,我怎麼把它的價值呢?例如對於例如 $image = trim($entry-> 'IMAGEURL' ?);

function getTweets($hash_tag) { 
    $url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag).'&rpp=5&include_entities=true&result_type=recent'; 

    //echo "<p>Connecting to <strong>$url</strong> ...</p>"; 
    $ch = curl_init($url); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $xml = curl_exec ($ch); 
    curl_close ($ch); 

    $affected = 0; 
    $twelement = new SimpleXMLElement($xml); 
    foreach ($twelement->entry as $entry) { 
     $text = trim($entry->title); 
     $author = trim($entry->author->name); 
     $time = strtotime($entry->published); 

     $id = $entry->id; 

回答

0

您可以嘗試SimpleXMLElement::attributes

$twelement = new SimpleXMLElement($xml); 
foreach ($twelement->children() as $entry) { 
     $arr = $entry->attributes(); // returns an array 
     print ("href =".$arr["href"]); // get the value of this attribute 

} 
+0

我試過,但我對如何檢索出來的圖像 – 2012-01-10 08:05:08

+0

看到更新後的答案不知道。 – 2012-01-10 09:30:52