why do i get query twice

radiant

New Member
I'm trying to basically extract the ?v= (the query part) of the youtube.com url... it's to automatically embed the video when someone types in a youtube.com URI (i.e. someone will type in http://www.youtube.com/?v=xyz, this program should embed it into the page automatically).Anyway when I run the following code, I get two QUERY(ies) for the first URI:\[code\]<?php//REGEX CONTROLLER://embedding youtube:function youtubeEmbedd($text){ //scan text and find: // http://www.youtube.com/ // www.youtube.com/$youtube_pattern = "(http\:\/\/www\.youtube\.com\/(watch)??\?v\=[a-zA-Z0-9]+(\&[a-z]\=[a-zA-Z0-9])*?)"; // the pattern #"http://www.youtube.com/?v=" echo "<hr/>"; $links = preg_match_all($youtube_pattern, $text, $out, PREG_SET_ORDER); // use preg_replace here if ($links) { for ($i = 0; $i != count($out); $i++) { echo "<b><u> URL </b><br/></u> "; foreach ($out[$i] as $url) { // split url[QUERY] here and replaces it with embed code: $youtube = parse_url($url); echo "QUERY: " . $youtube["query"] . "<br/>"; #$pos = strpos($url, "?v="); } } } else { echo "no match"; }}youtubeEmbedd("tthe quick gorw fox http://www.youtube.com/watch?v=5qm8PH4xAss&x=4dD&k=58J8 and http://www.youtube.com/?v=Dd3df4e ");?>\[/code\]Output is:\[quote\] \[code\]URL QUERY: v=5qm8PH4xAss QUERY: << WHY DOES THIS APPEAR???????????? URL QUERY: v=Dd3df4e\[/code\]\[/quote\]I would be greatful for any help.
 
Back
Top