2

Is it possible to extract the value of "image_url" from this link

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

and display as <img src=""> using php?

3
  • 1
    Yes, Download the result of the Link as a string, looks like its giving a JSON . so then access the JSON array "images" and get the "image_url" property. Commented Dec 28, 2016 at 4:13
  • @cwishva thanks will try that Commented Dec 28, 2016 at 4:15
  • take a look at this answer : stackoverflow.com/questions/15617512/get-json-object-from-url Commented Dec 28, 2016 at 5:12

2 Answers 2

1

You can fetch data from json as follow

<?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."'>";
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply
0

Thanks guys, I found a solution.

I will also post my solution here just in case other will encounter the same problem

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.