$.getJSON PHP alternative

$.getJSON might be misleading, but what I want to do is get JSON from a url via a PHP file.

var url = "https://script.google.com/macros/s/XXXXXXXXXX/exec?action=read";
$.getJSON(url, function (json) {

This works fine in javascript. When I google get JSON from url maybe it's because I'm learning PHP but I can't seem to find an answer that works. Or when I google $.getJSON I get people trying to get Json from a PHP file.

All my data is stored via a googlesheet that I access by calling google script and it sends it back and I can take the information I want e.g


I want to pass some data to a PHP file that I can't fathom how to do that.

Any help would be greatly appreciated.

1 answer

  • answered 2020-06-02 09:30 bangnokia

    It's simple as js:

    $content = file_get_contents('https://script.google.com/macros/s/XXXXXXXXXX/exec?action=read');
    $data = json_decode($content); // return object
    $data = json_decode($content, true); // return array