0

Possible Duplicate:
get the value of an url response with curl

I have the json url as follow

www.example.com/hello.php?action=get&id=18&format=json

which returns output as {"id":18,"name":"Dharma"}.

How can I get the name property by using php curl function?

I want output as "Dharma".

Community
  • 1
  • 1
  • Thx i am trying to get the out by using CURL in php – Anitha Selvam May 24 '12 at 11:06
  • 1
    `$str = file_get_contents('http://www.example.com/hello.php?action=get&id=18&format=json'); $json = json_decode($str, TRUE); echo $json['name'];` – DaveRandom May 24 '12 at 11:13
  • By Using Curl you can only get the JSON data not retreive any info from it unless you do a brute force method and split it , JSON decode is the way to go – GoodSp33d May 24 '12 at 11:14

1 Answers1

2

You don't need cURL for that, simply use

$content = file_get_contents('http://www.example.com/hello.php?action=get&id=18&format=json‌'); 
$array = json_decode($str, TRUE); 
echo $array['name'];
slash197
  • 9,028
  • 6
  • 41
  • 70
  • 1
    Thanks. I am learning CURL that's why i am expecting the result in only CURL in php – Anitha Selvam May 24 '12 at 11:46
  • @AnithaSelvam It does not matter which one you use. Think. The important part is the `json_decode()`. – kapa May 25 '12 at 10:48
  • The person posting the question specifically requested an example of cUrl usage. They said they're learning curl - don't see anything wrong if someone is wanting to learn something. – blispr Jun 05 '12 at 03:25
  • That $str should be $content, then it works! – kaleazy Jun 25 '13 at 09:08