In PHP, How to search and match a specific string with JSON data?
I have a bunch of strings and I want to know if they exist in the JSON response.
I used the following code but it is not working. I do not want to loop through the JSON data.
$url = "https://graph.facebook.com/me/feed?access_token=".$session['access_token'];
$page=file_get_contents($url);
$json_a = json_decode($page,true);
$pos = strpos($page, $mystring);
if($pos == true)
{
do something
}
$page does not contain a string with the contents of the JSON feed. How to convert JSON to string so I can check for $mystring ?
EDIT:
This is strange. When I use the url https://graph.facebook.com/me/feed?access_token=".$session['access_token']
I get empty data, but when I use "https://graph.facebook.com/me/friends?access_token=".$session['access_token'];
Everything is fine and I get the list of all my frien开发者_如何学JAVAds. I am not able to understand where I am going wrong?
This is the link http://developers.facebook.com/docs/reference/api/ I used the exact url format for Profile feed (Wall): https://graph.facebook.com/me/feed?access_token=...
JSON IS a string, until you run it through the decode function and its gets converted to a php structure. You should be able to do
if (strpos($page, "your search string") !== FALSE) {
echo "hey, it's in there";
}
If your $page is coming out blank, then your file_get_contents call is failing somehow.
精彩评论