Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Need help writing a regex to convert a YouTube Embed URL.

  •  04-15-2008, 12:27 PM

    Need help writing a regex to convert a YouTube Embed URL.

    Hello, I'm modifying some code that scans through an html document, and converts YouTube links to a URL of our server with $replacement1+ the YouTube ID as a URL parameter "url" (which you can see in the last line).  Everything seems ok, I just can't figure out the line for $pattern1.  I've tried probably 100 things with no luck.  I've left it here as ??????????? so it shows up well.  As you can see the embed src shows up in the $2 string.  The language I'm using is PHP. 

    An example YouTube Embed URL is:

    http://www.youtube.com/v/i4dLGAx2Q_s&hl=en

    ...and if everything works right it should convert to... 

    http://video.-------------.com/wsw?ct=Video&url=http://youtube.com/watch?v=i4dLGAx2Q_s   

    ...where i4dLGAx2Q_s is the piece I need to send as that URL parameter in the last line below. (It appears YouTube IDs can be alphanumeric + underscores and possibly dashes.)

    Thank you so much. I've been kicking this around for two days and I've had no luck. :( -Jason

     ......

      ......

            if(!$this->embed) // handle videos
            {
               
                //images without alt
                $search[]  = "/<embed[^>]* src=(\"([^\"]+)\"|'([^']+)'|([^\"'> ]+))[^>]*>/ie";
                       
                            $s1 = "$2";
                            $pattern1 = "???????????";
                            $replacement1= "http://www.youtube.com/watch?v=\\2";
                            $newurl = ereg_replace($pattern1, $replacement1, $s1);
                           
                $replace[] = "'[<a href=\'http://video.-------------.com/wsw?ct=Video&url='.'$newurl'.'\' />Watch Video</a>]'";
            }

    ......

    ......
     

    Filed under: , , , , ,
View Complete Thread