1

I need to take a img link (https://upload.wikimedia.org/wikipedia/en/5/51/Minecraft_cover.png) from this api https://en.wikipedia.org/w/api.php?action=query&prop=pageimages&format=json&piprop=original&titles=Minecraft&pilicense=any. How to do it?

I wrote code like this, but I can print :

$img_url = "https://en.wikipedia.org/w/api.php?action=query&prop=pageimages&format=json&piprop=original&titles=Minecraft&pilicense=any";
$img_url = str_replace(" ", "%20", $img_url);
$img = json_decode(file_get_contents($img_url));
print_r ($img);

But how to print only img source?

Stawikendo
  • 15
  • 5

1 Answers1

1

The simplest way would be to use the following.

echo $img->query->pages->{'27815578'}->original->source;

Where 27815578 is the Page ID

Uzair Hayat
  • 518
  • 1
  • 8
  • 21