Urgent help needed in Megavideo Regex

Discussion in 'PHP' started by gibigbig, Oct 3, 2010.

  1. #1
    The bulk code i have looks like this:
    function setembedcode(cwidth,cheight)
    {
      
      document.getElementById('embedcode').value = '<object width="' + cwidth + '" height="' + cheight + '"><param name="movie" value="http://www.megavideo.com/v/ZDWFCCMEf5a91463ba9f5539ffffde18eaa9acbf"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.megavideo.com/v/ZDWFCCMEf5a91463ba9f5539ffffde18eaa9acbf" type="application/x-shockwave-flash" allowfullscreen="true" width="' + cwidth + '" height="' + cheight + '"></embed></object>';
      
    }
     
    Code (markup):
    and I need a regular expression to match ONLY the
    http://www.megavideo.com/v/ZDWFCCMEf5a91463ba9f5539ffffde18eaa9acbf

    Can anyone help me?

    My current code is :
    $embed = file_get_contents($stream_link);
    	preg_match_all( '/http\:\/\/www\.megavideo\.com\/v\/(.*)\"\>/i', $embed, $matches, PREG_SET_ORDER);  
    	foreach($matches as $txt){
    		echo $txt[0].'<br />';
    	}  
    PHP:
     
    gibigbig, Oct 3, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, gibigbig,

    Try this code:
    
    $embed='function setembedcode(cwidth,cheight)
    {
      
      document.getElementById(\'embedcode\').value = \'<object width="\' + cwidth + \'" height="\' + cheight + \'"><param name="movie" value="http://www.megavideo.com/v/ZDWFCCMEf5a91463ba9f5539ffffde18eaa9acbf"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.megavideo.com/v/ZDWFCCMEf5a91463ba9f5539ffffde18eaa9acbf" type="application/x-shockwave-flash" allowfullscreen="true" width="\' + cwidth + \'" height="\' + cheight + \'"></embed></object>\';
      
    }';
    preg_match_all( '#(http\://)?(w{3}\.)?megavideo\.com/v/([a-z0-9]+)#im', $embed, $matches, PREG_SET_ORDER);    
    $matches=array_unique($matches);
        foreach($matches as $txt){
            echo 'http://www.megavideo.com/v/'.$txt[3].'<br />';
        }
    
    PHP:
    Regards :)
     
    koko5, Oct 3, 2010 IP