I'm trying to format the following number from a json url.
1835488750000000
to
18,354,887
Here is my code
$json_url = $Api;
$json = file_get_contents($json_url);
$data = json_decode($json, true);
$total = $data['value'];
echo number_format(trim($total , 0));
It returns
1.83549E+15
I'm tying to format the value of totalbc from the api url
Thank you
You could divide it by 1E8 and use number_format:
number_format(1835488750000000/1E8);
Related
I am trying to format the data passed by the api in to key value paris for use with javascript the data right now is one big key and not in key value paris how can i get the data as key value paris and properly formated ?
<?php
header('Content-Type: application/json; charset=utf-8');
$url = file_get_contents('https://www.jiosaavn.com/api.php?_format=json&query=mere%20angne%20mein&__call=autocomplete.get');
$data = explode('[', $url);
$format = json_encode($data[1], true);
print_r($format);
?>
The response contains some HTML which has to be removed to be able to parse the json. This can be achieved with strip_tags. After removing the html json_decode can be used to get the values:
<?php
$content = file_get_contents('https://www.jiosaavn.com/api.php?_format=json&query=mere%20angne%20mein&__call=autocomplete.get');
$content = strip_tags($content);
$response = json_decode($content);
print_r($response);
foreach($response->albums->data as $album){
echo $album->title;
}
result:
Mere Angne MeinLaawarisMere Angne MeinMere Angne Mein (From "Mere Angne Mein")Mere Angane Mein
$url = 'https://www.jiosaavn.com/api.php_format=json&query=mere%20angne%20mein&__call=autocomplete.get';
$data = file_get_contents($url);
$format = json_decode($data);
print_r($format);
I'm trying to get current USD/EUR rate using this api link:
http://api.fixer.io/latest?base=USD&symbols=EUR
Using this code:
$url = "http://api.fixer.io/latest?base=USD&symbols=EUR";
$json = json_decode(file_get_contents($url), true);
$price = $json->rates[0]->EUR;
I want result of $price to be like: "0.84782",
but it seems I'm doing something wrong?
<?php
$url = "http://api.fixer.io/latest?base=USD&symbols=EUR";
$json = json_decode(file_get_contents($url), true);
$price=$json['rates']['EUR'];
echo $price;
This will work for you. The price you are looking for is a nested array so you must first access the parent one.
You are passing true to json_decode, so the returned value is an array. To use object instead, remove true, like so:
$json = json_decode(file_get_contents($url));
Access it like this:
echo $json->rates->EUR; // Output is: 0.84782
If you want to access array style:
$json = json_decode(file_get_contents($url), true);
echo $json['rates']['EUR']; // 0.84782
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
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'm trying to turn a JSON file of Xbox Live data into variables that I can use in a PHP generated image. My JSON file is here: http://www.xboxgamercard.org/gamercard/test3/xbox.php
I have tried this:
$request_url = 'xbox.php';
$json = file_get_contents($request_url);
$decode = json_decode($json, true);
var_dump($decode['gamertag'][0]);
but it just returns NULL.
I would like to use the JSON as shown here:
$gamertag = $data['Gamertag'];
echo $gamertag;
You need to add the full url eg:
<?php
$request_url = 'http://www.xboxgamercard.org/gamercard/test3/xbox.php';
$json = file_get_contents($request_url);
$data = json_decode($json, true);
//Example output
echo $data['gamertag']; //Crylics
echo $data['gamerscore']; //7492
/* Too access the recent_games key you will need
to loop through it or access it like
*/
echo $data['recent_games'][1]['title']; //Call of Duty: WaW
?>