php - 正确的语法以在iframe中回显变量

标签 php wordpress variables iframe youtube

我知道我缺少一些简单的东西。如果$ video-code存在,我只想显示此iframe。谁能看到这有什么问题吗?在WordPress中工作。错误在回声线上。我也尝试添加。'$ video-code'。进入网址。

它正确显示了iframe,但变量在网址中显示为文本。如果我在没有If语句的情况下在页面的其他位置调用变量,它将正确显示。

谢谢你的帮助!

<?php
$key = 'video-code';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta != '') {
echo '<iframe id="player" width="560" height="315" frameborder="2"     src="http://www.youtube.com/embed/$video-code" ></iframe>';
}?>

最佳答案

您可以连接$key,如下所示:

echo '<iframe id="player" width="560" height="315" frameborder="2" 
src="http://www.youtube.com/embed/' . $key . '" ></iframe>';

关于php - 正确的语法以在iframe中回显变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17824573/

相关文章:

php - 在 Scriptaculous 中传递自动完成中的 ID 值

php - Magento 每个商店的价格不同

javascript - WordPress的。添加后html代码消失

c# - 发送对变量的引用而不是它的值

variables - Date 变量类型的默认值是否有 const,字符串类型有 vbNullString 的默认值?

php - Woocommerce 产品 api 不接受某些网址中的图片

javascript - 客户端和服务器端编程有什么区别?

css - 如何在 WordPress 的文本小部件中定位特定的文本行?

php - 在 WooCommerce 中先显示当前类别,然后显示子类别

mysql - 组合 INSERT SELECT 和 VARIABLES