I have created a function which will set height, width and wmode=transparent for youtube embed codes. Now youtube is returning iframe code. So, I need to append "?wmode=transparent" at the end of youtube src.
For eg.
Original code :
<iframe title="YouTube video player" width="420" height="349" src="http://www.youtube.com/embed/aXNUL1-urg8" frameborder="0" allowfullscreen=""></iframe>
I want it to be replaced with :
<iframe title="YouTube video player" width=" mywidth" height=" myheight" src="http://www.youtube.com/embed/aXNUL1-urg8 ?wmode=transparent" frameborder="0" allowfullscreen=""></iframe>
Replacing height and width is working, but replacing src does not work.
I am using below regex
$patterns[] = '/src="http:\/\/www.youtube.com\/embed\/[a-zA-Z0-9._-]"/';
$replacements[] = 'src="http://www.youtube.com/embed/${1}?wmode=transparent"';
Below is my function.
function SetHeightWidthVideo($markup,$w='200',$h='120') { //to make it wmode = transparent
$markup = str_replace('<embed ','<embed wmode="transparent" ',$markup); //$w = '200'; //$h = '120'; $patterns = array(); $replacements = array(); if( !empty($w) ) { $patterns[] = '/width="([0-9]+)"/'; $patterns[] = '/width:([0-9]+)/'; $replacements[] = 'width="'.$w.'"'; $replacements[] = 'width:'.$w; } if( !empty($h) ) { $patterns[] = '/height="([0-9]+)"/'; $patterns[] = '/height:([0-9]+)/'; $replacements[] = 'height="'.$h.'"'; $replacements[] = 'height:'.$h; } $patterns[] = '/src="http:\/\/www\.youtube\.com\/embed\/[a-zA-Z0-9._-]"/'; $replacements[] = 'src="http://www.youtube.com/embed/${1}?wmode=transparent"'; return preg_replace($patterns, $replacements, $markup);
}
Please help. Thanks in advance.
copy, paste, run:
try: