Jump to content

Recommended Posts

<?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.

 

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.