I'm trying to play with a web service via REST.
I finally am getting the results I want (or at least I think I am), but am unaware what to do with it. The response format is JSON.. I try outputting it via json_decode() to get it as an array, then I could do something with it.
You can see that I am getting "something" as a response as I am echoing the url that I am CURL'ing
I know this is a matter of education, but this is my first jaunt at this, so any help is appreciated. Again, my end goal is to obviously output the data in a readable format.
<?php
if(isset($_GET['word']))
{
$result= get_response_json($_GET['word']);
} else {$result = "";}
function get_response_json($word)
{
$postURL = "http://rhymebrain.com/talk?function=getRhymes&word=".urlencode($word);
echo $postURL;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postURL);
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_POST, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>
<html>
<title>Test Rhyme</title>
<body>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="get">
<input type="input" name="word" />
<input type="submit" value="Submit" />
</form>
<div id="results">
<?php
print_r(json_decode($result, true));
?>
</div>
</body>
</html>