Request API Data with JavaScript or PHP (Access a Json data with PHP API)


PHOTO EMBED

Tue Jan 12 2021 05:26:01 GMT+0000 (UTC)

Saved by @mvieira #php

// json data
;[
  {
    name: 'Aragorn',
    race: 'Human',
  },
  {
    name: 'Legolas',
    race: 'Elf',
  },
  {
    name: 'Gimli',
    race: 'Dwarf',
  },
]

$url = 'data.json'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data); // decode the JSON feed
content_copyCOPY

https://www.taniarascia.com/how-to-use-json-data-with-php-or-javascript/