我想嵌入youtube链接,但我也想嵌入来自['url']
的链接。
我没有收到任何错误的php消息。我的php代码是:
$search = '#<iframe(.*?)(?:href="https?://)?(?:www'.)?(?:youtu'.be/|youtube'.com(?:/embed/|/v/|/watch?.*?v=))(['w'-]{10,12}).*<'/iframe>#x';
$replace = '<iframe width="560" height="315" src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>';
$text = preg_replace($search, $replace, $text);
而 iframe :
echo ' <iframe class="video" allowfullscreen style="overflow-x: hidden; overflow-y: hidden;" width="658px" height="569" frameborder="0" src="'.$row['url'].$text.'"></iframe>' ;
如果您给一个 youtube 链接,我现在想解决这个问题,输出如下所示:
<iframe class="video" allowfullscreen="" style="overflow-x: hidden; overflow-y: hidden;" width="658px" height="569" frameborder="0" src="https://www.youtube.com/watch?v=dh-0jH4Rb7Y"></iframe>
为什么不直接使用:
$fullUrl = //put here anything you want, be it result from MySQL or $_POST
echo ' <iframe class="video" allowfullscreen style="overflow-x: hidden; overflow-y: hidden;" width="658px" height="569" frameborder="0" src="'.$fullUrl.'"></iframe>' ;
并决定$fullUrl
应该在回声之前做什么?要使preg_replace无法回显工作,您需要先将其分配给变量。为什么要自己preg_replace变量分配的东西?浪费内存和时间。