Php 为什么不在iframe中使用preg应答?

Php 为什么不在iframe中使用preg应答?,php,iframe,preg-replace,Php,Iframe,Preg Replace,我想嵌入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" heig

我想嵌入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正常工作,您需要首先将其分配给变量。为什么你想用变量替换你自己分配的东西?浪费记忆和时间

你想从数据库中获取youtube链接并将其放入iframe?是的,但我也想嵌入[url]字段中给定的链接。因为那里有任何可能的链接。因此,如果用户提供的不同url不包含youtube url,也应该嵌入。你的意思是我必须在一个页面中使用两个iframe,因为youtube?我想在iframe上解决这个问题,如果它是一个链接,我想嵌入一个html文件。但如果你只是一个youtube链接,如果它可以嵌入,那就太好了。