检索Twitter Tweet实体Image的URL PHP

时间:2012-01-10 07:49:11

标签: php twitter simplexml

我有这个功能来使用twitter的搜索API

我想获得推文的显示图像。 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;

1 个答案:

答案 0 :(得分: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

}