【问题标题】:Extracting "image_url" value and display as image src提取“image_url”值并显示为图像 src
【发布时间】:2017-05-12 07:59:39
【问题描述】:

是否可以从此链接中提取“image_url”的值

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

并使用 php 显示为<img src="">

【问题讨论】:

标签: php


【解决方案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."'>";
?>

【讨论】:

  • 感谢您的回复
【解决方案2】:

谢谢大家,我找到了解决办法。

我也会在这里发布我的解决方案,以防其他人遇到同样的问题

    <?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
}
?> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 2019-06-13
    相关资源
    最近更新 更多