0

I've been using parse_url and parse_str in order to get the ?v= from youtube.com links, unfortunatly it seems youtube passes video ID's that begin with both underscores and hyphens.

As a result,

$url = parse_url($url);
$vid = parse_str($url['query'], $output);
$video_id = $output['v'];

Gives me malformed ID's where -'s are changed to _ - Is there anyway to tell parse_url, parse_str to not exhibit this behaviour? or some other work around?

Ideally I want to avoid regex..

Liam Closs
  • 55
  • 1
  • 7
  • 2
    It seems fine to me: http://codepad.viper-7.com/2B8ByK – j0k Aug 27 '12 at 20:38
  • http://www.youtube.com/watch?v=-KTo1Nxyp1A&feature=plcp http://www.youtube.com/watch?v=-7y2pIZqPrU&feature=plcp http://www.youtube.com/watch?v=vqT-1krLL90&feature=plcp http://www.youtube.com/watch?v=-DDIFWBufrY&feature=plcp http://www.youtube.com/watch?v=-qolAwvSjkY&feature=plcp for example all give $video_id's that aren't a genuine reflection of $v= due to parse_url and parse_str – Liam Closs Aug 28 '12 at 00:00
  • I have taken a closer look at this and I can actually get it work with all of those URLs just fine, I am unsure why yours aint working. – Sammaye Aug 28 '12 at 17:31
  • 1
    This appears to be a PHP bug. It works fine on 5.3.10 but not 5.3.13. (I'm having the same issue.) – Samutz Mar 22 '13 at 17:23

0 Answers0