jeger003 Posted August 14, 2010 Share Posted August 14, 2010 hello, I am trying to figure out how I can take only the v= in the youtube urls i just want php to take v=nGawAhRjtoA and ignore everything else any ideas guys/gals? thanks Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/ Share on other sites More sharing options...
MadTechie Posted August 15, 2010 Share Posted August 15, 2010 try this *untested* $url = "http://www.youtube.com/watch?v=nGawAhRjtoA&feature=topvideos"; if (preg_match('/v=([^&]+)/i', $url,$match)) { echo "Found: ".$match[1]; } else { echo "No V found"; } Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099400 Share on other sites More sharing options...
jeger003 Posted August 15, 2010 Author Share Posted August 15, 2010 man you are AWESOME!!!! I tested it and it works GREAT!!!! thank you Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099404 Share on other sites More sharing options...
jeger003 Posted August 15, 2010 Author Share Posted August 15, 2010 there is one more thing i need help with basically the v= code is taken to display the youtube video right under the form my issue is....I have no clue how to take the v=code out in the POST or GET in a FORM why.....because a URL (YOUTUBE) wont work in the URL bar ( i.e. www.mysite.com/video.php?youtubeURL=http://www.youtube.com?v=AkdfOsdfj) this wont work I want users to enter url then use MadTechie's code to get V and use that to get the video does this make sense? thanks again guys/gals Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099422 Share on other sites More sharing options...
MadTechie Posted August 15, 2010 Share Posted August 15, 2010 Here is a example with a form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TITLE</title> </head> <body> <form action="" method="get"> <input name="URL" type="text" value="http://www.youtube.com?v=AkdfOsdfj" size="65" /><BR /> <input name="RUN" type="submit" value="Run IT" /> </form> <?php if(!empty($_GET['URL'])){ if (preg_match('/v=([^&]+)/i', $_GET['URL'],$match)) { echo "Found: ".$match[1]; } else { echo "No V found"; } } ?> </body> </html> you can change the method from get to post but then your need to update the 2 $_GET to $_POST OH yeah and if you wanted your example URL to work why.....because a URL (YOUTUBE) wont work in the URL bar ( i.e. www.mysite.com/video.php?youtubeURL=http://www.youtube.com?v=AkdfOsdfj) this wont work use this code <?php if(!empty($_GET['youtubeURL'])){ if (preg_match('/v=([^&]+)/i', $_GET['youtubeURL'],$match)) { echo "Found: ".$match[1]; } else { echo "No V found"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099424 Share on other sites More sharing options...
jeger003 Posted August 15, 2010 Author Share Posted August 15, 2010 thanks MadTechie i end up running into the same issue....when i click run it i get sent to my home page and this is what the URL looks like http://mysite.com/url-test.php?URL=http%3A%2F%2Fwww.youtube.com%3Fv%3DAkdfOsdfj&RUN=Run+IT I'm not able to get v= out by the way im testing this in IE and FFX and same issue thank you Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099429 Share on other sites More sharing options...
MadTechie Posted August 15, 2010 Share Posted August 15, 2010 the logic is the same, just change URL to yourtubURL tested in IE & FF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TITLE</title> </head> <body> <form action="" method="get"> <input name="youtubeURL" type="text" value="http://www.youtube.com?v=AkdfOsdfj" size="65" /><BR /> <input name="RUN" type="submit" value="Run IT" /> </form> <?php if(!empty($_GET['youtubeURL'])){ if (preg_match('/v=([^&]+)/i', $_GET['youtubeURL'],$match)) { echo "Found: ".$match[1]; } else { echo "No V found"; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099432 Share on other sites More sharing options...
jeger003 Posted August 15, 2010 Author Share Posted August 15, 2010 dude your awesome!!! for some reason GET didnt work for me so I changed it to POST and it works great somebody deserves an e-HUG thanks again!!! Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099433 Share on other sites More sharing options...
MadTechie Posted August 15, 2010 Share Posted August 15, 2010 lol, your very welcome Quote Link to comment https://forums.phpfreaks.com/topic/210748-youtube-url-extraction-help/#findComment-1099442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.