0
if($_POST['VIDEO']){
    $video = parse_url($_POST['VIDEO']);
    if($video['host'] == 'www.youtube.com' || $video['host'] == 'youtube.com'){
        $query = parse_str($video['query']);
        $v = $query['v'];
        if(!$v){
            //nothing found
        } else { 
            $videoOutput = 'yt:'.$v;
        }
    }
}

So I made this script about a month ago. Worked perfectly up until last night. I don't understand why. It works perfectly up until last night. It does in fact parse the url, and the host is valid. I get to parse_str and everything suddenly doesn't work. I did print_r of $query and it returns no data. If I echo the variable though, I get a 1. This file hasn't even been touched, so I don't understand why it would have suddenly broke.

Any suggestions?

Jake
  • 1,469
  • 4
  • 19
  • 40
  • You might be looking for `preg_match('/https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w]*(?:[\'"][^<>]*>|<\/a>))[?=&+%\w-]*/i', $_POST["VIDEO"], $match)` – h2ooooooo Feb 22 '13 at 19:56
  • Checkout full examples on this site: http://stackoverflow.com/questions/4602956/youtube-get-video-not-working Some people have problems with YT links which not working correctly. Maybe should change better code as example on above. – Marin Sagovac Feb 22 '13 at 19:56

3 Answers3

5

Bad syntax: parse_str doesn't return anything. To parse $string into an array called $array:

parse_str($string, $array)
DiMono
  • 3,308
  • 2
  • 19
  • 40
  • Thank you much, will accept when it lets me (9 minutes). Funny thing is, I was told that works by someone on here. And it actually did work for about a month. Slightly confused on what happened, but glad it's fixed. – Jake Feb 22 '13 at 19:56
1

If you read the documentation for parse_str(), you'll see that it returns nothing (void) if you use it without the second argument.

Try this instead:

parse_str($video['query'], $query);

if (!$query['v']) {
  ...
}
silkfire
  • 24,585
  • 15
  • 82
  • 105
0

according to the documentation and the samples from php.com you have to do this:

$query = array(); 
parse_str($video['query'],$query);
EGOrecords
  • 1,959
  • 2
  • 19
  • 33