<?php
$url = "http://api.giphy.com/v1/gifs/search?q=hello&api_key=dc6zaTOxFJmzC";
$content = file_get_contents($url);
$json = json_decode($content);
echo $json->images[0]->fixedheight->url[0];
?>
I've tried everything- even reading it as an array and it doesn't work.
Any help?
So sorry to bother! Thanks again.
You should access it this way
echo $json->data[0]->images->fixed_height->url;
That is beacause the $data is an array , and it has an object as its first parameter.
use this
<?php
$url = "http://api.giphy.com/v1/gifs/search?q=hello&api_key=dc6zaTOxFJmzC";
$content = file_get_contents($url);
$json = json_decode($content);
echo "<pre>";
print_r($json->data[0]->images->fixed_height->url);
exit;
?>
Related
http://simsimi.com/getRealtimeReq?uuid=VbQqwsQ3qiCw1T04VrrFQzBBlkfZibg3YFkbWz6VquZ&lc=id&ft=1&reqText=Eh+jelek&status=W
How to get value from respSentence
Im using php lang ^_^
" {"status":200,"respSentence" 11 \:"respSentence"}"` is not valid json. Use some online sites to validate your json and try like this,
$json = '{"status":200,"respSentence" :"iyas"}';
$array = json_decode($json, true);
echo $array ['respSentence'];
You can try using file_get_contents and json_decode PHP functions
$url = "http://simsimi.com/........";
$data = file_get_contents($url);
$json = json_decode($data, true);
echo $json ['respSentence'];
hope it helps
Here is my data.php
$global = $pdo->query("SELECT name, age");
$global = $global->fetchAll(PDO::FETCH_ASSOC);
$arr = array('data'=>$global);
echo json_encode($arr, JSON_PRETTY_PRINT);
Here is my index.php
<html>
<?php
$json_url = "data.php";
$json = utf8_encode(file_get_contents($json_url));
$data = json_decode($json, false);
echo "<pre>";
print_r($data);
echo "</pre>";
?>
</html>
I get blank data. What am I doing wrong?
Try this:
$query = "SELECT * FROM table";
$stmt = $pdo->query($query);
$global= $stmt->fetchAll(PDO::FETCH_ASSOC);
$arr = array('data'=>$global);
echo json_encode($arr);
//echo json_encode($arr, JSON_PRETTY_PRINT);
First of all make sure file_get_contents is actually returning something.
If not, check your logs to see what file its actually requesting. Use a full-path ex: http://location/path/to/data.php
I have had issues with reading JSON without setting the Content-Type.
header('Content-Type: application/json')
Help me to grab name of games from url
This page output json format.
I try to convert it to array, but my code not work. Please help me!
$url = 'https://search.g2a.com/items/select?json.wrf=jQuery111003403934023808688_1411464896728&q=NOT+type%3Aindividual+AND+(-type%3Agaming+AND+wholesaleQty%3A%5B1+TO+*%5D+AND+wholesaleMinPrice%3A%5B0+TO+198%5D)&wt=json&start=0&rows=10000&sort=sortOrder+DESC&_=1411464896757';
$content = file_get_contents($url);
$json = json_decode($content, true);
echo "<pre>";
print_r($json);
echo "</pre>";
You should remove the JSONP parameter json.wrf from the URL first:
https://search.g2a.com/items/select?q=NOT+type%3Aindividual+AND+(-type%3Agaming+AND+wholesaleQty%3A%5B1+TO+*%5D+AND+wholesaleMinPrice%3A%5B0+TO+198%5D)&wt=json&start=0&rows=10000&sort=sortOrder+DESC&_=1411464896757
This will return a proper JSON result.
The output from that URL (that I get currently starts with):
jQuery111003403934023808688_1411464896728({"responseHeader" ...
This isn't a pure JSON response, but rather a JSONP response.
If you're just trying to parse it in PHP, maybe something like:
$url = ...; // Your URL Here
$data = file_get_contents($url);
$pos = strpos($data, '{');
$data = substr($data, $pos, strlen($data) - $pos - 2);
$json = json_decode($data, true);
echo "<pre>";
print_r($json);
echo "</pre>";
I would like to trnsform some JSON data to a php array, this is my code:
<?php
$obj1=json_decode('http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json', true);
$championname = $obj1[data][aatrox][name];
echo $championname;
?>
The problem is that i don't know how to get the data from http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json
How can i make this code work?
Try with file_get_contents() like this:
$json = file_get_contents('http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json');
$obj1 = json_decode($json , true);
$championname = $obj1['data']['aatrox']['name'];
echo $championname;
Use file_get_contents to download a file.
$json = file_get_contents('http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json');
$obj1 = json_decode($json, true);
I am trying to get this to work but can't see where I'm going wrong. Can anyone assist?
<?php
$jsonurl = 'http://www.foxsports.com.au/internal-syndication/json/livescoreboard';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = var_dump(json_decode($json,true));
echo $json_output
?>
Hint :
The initial JSON (stored in $json variable) does NOT validate.
Code : (FIXED)
<?php
$jsonurl='http://www.foxsports.com.au/internal-syndication/json/livescoreboard';
$json = file_get_contents($jsonurl,0,null,null);
$json = strip_tags(str_replace("jQuery.fs['scoreboard'].data =","",$json));
$json_output = var_dump(json_decode($json,true));
echo $json_output;
?>
This will work. :-)
Your JSON source is not valid. You can try this validator http://jsonlint.com/