2012-01-10 20 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