I got a response from the reddit API where the statistics from a link is made into a array. However, I can't figure out how to get the score-value from the response.
My current code:
http://pastebin.com/mH7udEKD
The response I get:
http://pastebin.com/N5smhxry
Should give you the score value:
$json_output['data']['children'][0]['data']['score']
it seems the only way to reach it is $json_result["data"]["children"][0]["data"]["score"].. are you sure this is the way to pull what you want from the API?
Just look at the response. Looks like this should do it:
$json_output['data']['children'][0]['data']['score']
Related
I have a cookie set in the format:
{"necessary":true,"functional":true,"advertising":false,"performance":true,"lastConsentReset":null}
or as it is in the dev console in Chrome:
%7B%22necessary%22%3Atrue%2C%22functional%22%3Atrue%2C%22advertising%22%3Afalse%2C%22performance%22%3Atrue%2C%22lastConsentReset%22%3Anull%7D
I would like to use PHP to read this cookie and return the value of the key "advertising".
I have looked around to try and find a solution but they all just show how to read a cookie with just one piece of data like this:
return $_COOKIE[ 'somecookie' ];
I imagine I need some sort of loop to search the array I just don't know how to do it.
Any help greatly appreciated!
thanks.
Its JSON and URL encoded, just reverse it:
echo json_decode(urldecode($_COOKIE['somecookie']))->advertising; // nothing as its false
I'm struggling to get JSON object with API link by PHP. (http://hots.adspreemedia.com/api/characters). This link should allow me to fetch a list of characters as JSON object.
What I tried was the following code.
<?php
$list = file_get_contents('http://hots.adspreemedia.com/api/characters');
echo $list;
?>
But it just shows only {"status":"200","message":"OK","data":[1,2,3,4]} in my localhost. My final goal is to create a list of characters in PHP file.
Follow the link you posted. it matches exactly what you are getting back.
To get more data, you will need to follow their api docs for retrieving more info from them
Is this a site you are building? there is no sigup form, and no documentation I can find without logging in to help you with
If you want to fetch [1,2,3,4] then do following
$list=json_decode($list,true);
$chars=$list['data']; //-- The array of characters
I am trying to start using APIs, doing calls and so forth. Just barely starting to learn. Found a way to get Facebook shares on a post using the graph api.
I did this with PHP; here is the code:
$response = file_get_contents('https://graph.facebook.com/? id=mydomain.com');
echo $response;
this is the response that I get:
{"id":"http://sportsmockery.com/2014/11/hey-bears-fire-everyone/","shares":22}
What I want is to somehow get the share count (22) into a variable so I can do stuff with it…(i changed the domain that gets that share count to my domain.com);
anyway; I am not sure what is the standard way to do this, if you control what is received with how you do your call; or if you just get the full response and pull out what you want…
Been looking around and have not been able to find anything that will really help with this.
I am hoping someone can help me with this…
All the best, G
Use json_decode() which will make all of the properties easily accessible.
$parsedResponse = json_decode($response);
$count = $parsedResponse->shares;
echo $count;
This is a json response.
Parsing JSON file with PHP
http://php.net/manual/en/function.json-decode.php
I have signed up to a synonym API.. see the details on this page
I am having trouble implementing this in my php code.
If I copy and paste the link into the web browser, I can see the results no problem.
Instead of typing the word in manually, I wish to have a variable in the link with the relevant word i.e. $variable_with_word_stored as shown below.
http://words.bighugelabs.com/api/2/xxxxxxxx/$variable_with_word_stored/php
//format could be php (I would unserialize)..or json..I could decode it?
Any ideas guys? Thanks.
It sounds like you mean you want the result from calling that webpage and store it in a variable. What you should be looking to do is sending a http get request to that page within the code.
Check out using curl with php, you can send a http request to your requested url, capture the result back and parse it through json_decode
http://php.net/manual/en/curl.examples-basic.php
try it like this, maybe that you dont need curl:
$key = "xxxxxxxx";
$word = "love";
echo file_get_contents("http://words.bighugelabs.com/api/2/$key/$word/php");
Are there any good, free ways to do this?
I found http://fonefinder.net, which looks okay. If that's my best best, how can I query it with a phone number and get the returned carrier? (I don't see an API).
Well, it looks like your query URL is as follows:
http://www.fonefinder.net/findome.php?npa={First Three}&nxx={Next Three}&thoublock={Last Four}
I would just get that page, use PHP's XML parser on the document. This should get you started:
<?php
$xmlDOC = simplexml_load_file(/* Your Request URL */);
print_r($xmlDOC->center->table[1]->tbody->tr[1]->td[4]->a->attributes());
?>
There is this website http://phonenumberprovider.com, for some reason it doesn't have a public API yet, but the developer told me that I can use this at the moment:
http://phonenumberprovider.com/api/json/+187605591648
Returns JSON like this:
{"result":"success","description":"Phone number provider found","operator":"JAMAICA","operatorPrefix":"1876","operatorCountry":"JM"}