我创建了一个函数,它将为 youtube 嵌入代码设置高度、宽度和 wmode=transparent 。现在 youtube 正在返回 iframe 代码。所以,我需要在 youtube src 的末尾附加“?wmode=transparent”。
例如。
原始代码:
我希望将其替换为:
VIDEO
替换高度和宽度有效,但替换 src 不起作用。
我正在使用下面的正则表达式
$patterns[] = '/src="http:\/\/www.youtube.com\/embed\/[a-zA-Z0-9._-]"/';
$replacements[] = 'src="http://www.youtube.com/embed/${1}?wmode=transparent"';
下面是我的功能。
函数SetHeightWidthVideo($markup,$w='200',$h='120')
{
//使其wmode =透明
$markup = str_replace('
}
请帮忙。提前致谢。
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.
发布评论
评论(2)
尝试:
try:
复制、粘贴、运行:
copy, paste, run: