简体   繁体   English

检索Twitter Tweet实体图像的URL PHP

[英]Retrieveing Twitter Tweet Entities Image's URL PHP

I have this function to use the search API from twitter 我具有使用Twitter的搜索API的功能

I want to get the display image of a tweet. 我想获取一条推文的显示图像。 The XML is displayed as this : XML显示如下:

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

how to i get its value out? 我如何获得其价值? for eg $image = trim($entry-> 'IMAGEURL' ?); 例如$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;

You can try SimpleXMLElement::attributes 您可以尝试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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM