correct syntax to echo variable inside iframe

北战南征 提交于 2020-01-06 08:14:40

问题


I know i am missing something simple. I just want to display this iframe if $video-code exists. Can anyone see what is wrong with this? working in wordpress. error is on the echo line. i've also tried adding .'$video-code'. into the url.

it is displaying the iframe correctly, but the variable is displaying as text in the url. if i call the variable elsewhere in the page without the If statement, it displays correctly.

THANKS for any help!

<?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>';
}?>

回答1:


You can concatenate your $key, like so:

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


来源:https://stackoverflow.com/questions/17824573/correct-syntax-to-echo-variable-inside-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!