salman_ahad@yahoo.com Posted October 23, 2009 Share Posted October 23, 2009 I am working with this API Returns JSON. curl http://letsbetrends.com/api/current_trends How to grab just the trending topics Which come after "name" : "xxxxxxxx" (the x's) Or how to work with curls ?? Quote Link to comment https://forums.phpfreaks.com/topic/178706-solved-how-to-grab-certain-words/ Share on other sites More sharing options...
Prismatic Posted October 23, 2009 Share Posted October 23, 2009 <?php $data = file_get_contents("http://letsbetrends.com/api/current_trends"); $json_data = json_decode($data, true); foreach($json_data as $branches) { foreach($branches as $entry) { if($entry['name'] == "Halloween") { print_r($entry); } } } ?> That will only display topics created by Halloween, for example. Quote Link to comment https://forums.phpfreaks.com/topic/178706-solved-how-to-grab-certain-words/#findComment-942670 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 23, 2009 Author Share Posted October 23, 2009 I think we are almost there. But we need to grab all the names as ['name']== "xxxx" (could be anything, not only Halloween) How to do this ? Quote Link to comment https://forums.phpfreaks.com/topic/178706-solved-how-to-grab-certain-words/#findComment-942961 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 23, 2009 Author Share Posted October 23, 2009 I got his error while running the code Warning: Invalid argument supplied for foreach() in foreach($branches as $entry) There are about 10 names there which keep changing, your code is only grabbing Halloween. If I run your code after four hours I will not know which are those 10 words. Please help Quote Link to comment https://forums.phpfreaks.com/topic/178706-solved-how-to-grab-certain-words/#findComment-942969 Share on other sites More sharing options...
salathe Posted October 23, 2009 Share Posted October 23, 2009 How to grab just the trending topics The following example script: <?php $json = file_get_contents('http://letsbetrends.com/api/current_trends'); $data = json_decode($json); $topics = array(); foreach ($data->trends as $trend) { $topics[] = $trend->name; } print_r($topics); Gives output like: Array ( [0] => Halloween [1] => Windows 7 [2] => Nick Griffin [3] => TGIF [4] => Paranormal Activity [5] => Follow Friday [6] => #iusuallylieabout [7] => Soupy Sales [8] => Cassetteboy [9] => #mylasttweetonearth ) $topics is an array of the trending topics, which I think is what you wanted. Quote Link to comment https://forums.phpfreaks.com/topic/178706-solved-how-to-grab-certain-words/#findComment-942994 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 23, 2009 Author Share Posted October 23, 2009 EXACTLY !! Thanks Dude Quote Link to comment https://forums.phpfreaks.com/topic/178706-solved-how-to-grab-certain-words/#findComment-943024 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.