【发布时间】:2011-10-14 13:45:00
【问题描述】:
我有一些带有图像的文本。我想用其他东西替换文本中的特定图像。
即文本包含一个 youtube img url,我想用实际的视频链接替换它。
<img class="mceItem" src="http://img.youtube.com/vi/1MsVzAkmds0/default.jpg" alt="1MsVzAkmds0">
并将其替换为 youtube Iframe 代码:
<iframe title="'.$id.'" class="youtube-player" type="text/html" width="576" height="400" src="http://www.youtube.com/embed/'.$id.'" frameborder="0"></iframe>
我的函数如下所示:
function replacelink($link) {
$find= ("/<img src=[^>]+\>/i");
$replace = youtube("\\2");
return preg_replace($find,$replace);
}
我需要在正则表达式中进行哪些更改才能执行上述操作?
【问题讨论】:
-
什么是“youtube”功能?
-
...如果我能获得图片的 alt 标签或 src,我可以将其发送到 youtube 函数 youtube($id){ return iframe code ?$id=1MsVzAkmds0 } 并显示 iframe而不是图片。
标签: php regex preg-replace