vendredi 31 juillet 2015

Regex doesn't save match in variable

I got URLs to different Youtube channels stored in my database. I am now trying to loop through all of them and check whether they still exist with the following code:

foreach ($pages as $page) {
    preg_match("/([^/]+$)/", $page['url'], $channelId);

    $channel = get_data('http://ift.tt/1DgFG4b'.$channelId[0].'&key='.$site['yt_api']);

    $channel = json_decode($channel, true);

    echo $channelId[0];
    echo $channel[pageInfo][totalResults];

    break;
}

The problem is that this test code doesn't print out $channelId[0] but only $channel[pageInfo][totalResults] which is 0 in this case due to some error with my regex. Could someone point out my error please?

Aucun commentaire:

Enregistrer un commentaire