-
Seperating data with PHP
I'm trying to figure out how to separate the id from a youtube url, however I can't use explode because after the id in the url there is nothing to explode.
http://www.youtube.com/watch?v=Q4pY3QtiGyo
I need to separate the bit in bold, however someone might imput an url like this-
http://www.youtube.com/watch?v=Q4pY3QtiGyo&feature=rec-fresh
Which would make exploding it even harder, any ideas?
-
PHP Code:
<?php
$str = "http://www.youtube.com/watch?v=Q4pY3QtiGyo&feature=rec-fresh";
if(eregi("&",$str))
{
$str = explode("v=",$str);
$str = explode("&",$str[1]);
$str = $str[0];
}
else
{
$str = explode("v=",$str);
$str = $str[1];
}
?>
I think that should cover all cases :P
-
Yeah, unfortunately that's the problem, the & sign isn't always there.
-
Ye i just realised and edited post :P
-