php preg_replace help iframe src
Criei uma função que definirá altura, largura e wmode = transparent para os códigos de incorporação do youtube. Agora o youtube está retornando o código iframe. Então, preciso anexar "? Wmode = transparent" no final do youtube src.
Por exemplo,
Código original:
<iframe title = "player de vídeo do YouTube" width = "420" height = "349" src = "http://www.youtube.com/embed/aXNUL1-urg8" frameborder = "0" allowfullscreen = ""> < / iframe>
Eu quero que ele seja substituído por:
<iframe title = "player de vídeo do YouTube" width = " mywidth "height ="minha altur "src =" http://www.youtube.com/embed/aXNUL1-urg8? wmode = transparent "frameborder =" 0 "allowfullscreen =" "> </iframe>
Substituir altura e largura está funcionando, mas a substituição do src não funcion
Estou usando abaixo o regex
$ patterns [] = '/src="http:\/\/www.youtube.com\/embed\/[a-zA-Z0-9._-)"/'
$ replaceements [] = 'src = "http://www.youtube.com/embed/${1}?wmode=transparent"';
Abaixo é a minha função.
function SetHeightWidthVideo (marcação $, $ w = '200', $ h = '120') {// para torná-lo 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);
}
Por favor ajude. Desde já, obrigado