2012-10-13 27 views
0

PHP的新功能,并发现一个可以从Twitter API中检索JSON数据并将其回显出来的可靠代码。下面是检索@Guardian的用户照片(报纸)回声图像 - PHP和JSON - Twitter的API

<?php 
    $data = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=guardian'), true); 
    echo $data[0]['profile_image_url']; 
?> 

对图像的JSON数据是PHP代码:

profile_image_url “:” http://a0.twimg.com /profile_images/1857791844/G_twittermain_normal.jpg”

所以,很显然它呼应的URL(文字),我想输出的实际图像,可能有超过它的尺寸控制得如果可能的话。

在此先感谢!

+0

?或者想要保存在您的服务器上前调整 – GBD

回答

1

<img src=" <?php echo $data[0]['profile_image_url'];?>" /> 
</body> 

要在HTML显示图像
+0

辉煌。谢谢! :D – nowthatsmint

+0

接受回答,以获得更多的帮助,从stackoverflow人:) –

+1

如果你输出一个URL到HTML上下文,你必须逃避它。 ' Sven