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?
Bad syntax: parse_str doesn't return anything. To parse $string into an array called $array:
parse_str($string, $array)
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']) {
...
}
according to the documentation and the samples from php.com you have to do this:
$query = array();
parse_str($video['query'],$query);