[英]Retrieveing Twitter Tweet Entities Image's URL PHP
我具有使用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;
您可以嘗試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.