0

I have API url looks like this: https://api.domain.demo/v1.1/employees/1?api_token=123456

when I click on it I got the following data:

{"id":1,"name":"Anna"}

How to display and format the response data in PHP page using GET method?

1
  • 2
    you have to use json_decode(the url) Commented Jul 30, 2016 at 19:39

2 Answers 2

2

json_decode() is what you are looking.

$link = "your url"

$data = json_decode($link,true);

after decoding the json, you will get a array with the elements in the json

print_r($data)
Sign up to request clarification or add additional context in comments.

Comments

1

It worked this way:

<?php
        $url = "https://api...";
        $data = json_decode(file_get_contents($url), true);
        echo "id: ", $data['id'];
        echo '<br>';
        echo "Name: ", $data['name'];
        echo '<br>';
        echo "Logo: ", '<img src="', $data['logo'], ' " height="30" width="30">';
?>

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.