2016-12-28 44 views
2

是否有可能从使用PHP此链接提取“IMAGE_URL”值而显示为图像的src

http://theapache64.xyz:8080/gpix/v1/gpix?keyword=honda%20civic%202009&limit=1

而显示为<img src="">提取物“IMAGE_URL”的值?

+1

是,下载链接为一个字符串的结果,看起来像它给人一种JSON。所以然后访问JSON数组“图像”并获得“image_url”属性。 – cwishva

+0

@cwishva谢谢你会尝试 –

+0

看看这个答案:http://stackoverflow.com/questions/15617512/get-json-object-from-url –

回答

1

您可以从JSON获取数据如下

<?php 
$content = file_get_contents('http://theapache64.xyz:8080/gpix/v1/gpix?keyword=honda%20civic%202009&limit=1'); 

$arr = json_decode($content,true); 

$url = $arr['data']['images'][0]['image_url']; 

echo "<img src='".$url."'>"; 
?> 
+0

感谢您的回复 –

0

谢谢你们,我找到了解决办法。

我还会在这里发布我的解决方案,以防万一对方也会遇到同样的问题

<?php 

$json_file = file_get_contents('http://theapache64.xyz:8080/gpix/v1/gpix?keyword='.$combineurl.'&limit=1'); 

$jfo = json_decode($json_file); 


$posts = $jfo->data->images; 



foreach ($posts as $post) { 
    ?> 
    <img src="<?php echo $post->image_url; ?>" alt="" width="500"> 
    <?php 
} 
?>