0

I'm trying to get the height and width of the retrieved Json string from cse, in PHP, but can't seem to find the correct syntax.

the JSON:

"items":[  
   {  
      "kind":"customsearch#result",
      "title":"INDUSTRIELL Vase - IKEA",
      "htmlTitle":"INDUSTRIELL \u003cb\u003eVase\u003c/b\u003e - IKEA",
      "link":"https://www.ikea.com/us/en/images/products/industriell-vase__0579791_PE669899_S4.JPG",
      "displayLink":"www.ikea.com",
      "snippet":"INDUSTRIELL Vase - IKEA",
      "htmlSnippet":"INDUSTRIELL \u003cb\u003eVase\u003c/b\u003e - IKEA",
      "mime":"image/jpeg",
      "image":{  
         "contextLink":"https://www.ikea.com/us/en/catalog/products/10387077/",
         "height":500,
         "width":500,
         "byteSize":13391,
         "thumbnailLink":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ8GgKi6WPRCOUuPHupIGdWXkW6o2_Fkxap6RIAsrTG7XqVMuDq1znO0jLVwQ",
         "thumbnailHeight":130,
         "thumbnailWidth":130
      }
   }

I reach "title" or "link" with no problems.

But can't find a code to get the height and width values. I would appreciate help on this subject. Thanks.

OhioStateB
  • 17
  • 6

1 Answers1

0

You could use:

<?php
$data = json_decode ( $json, true);
echo "Image width x height: " . $data["items"]["image"]["width"] . " x " . $data["items"]["image"]["height"] . PHP_EOL;
?>
Ernani Azevedo
  • 461
  • 2
  • 6