需要在引号内回显变量

时间:2017-06-09 18:12:17

标签: php iframe

我有这段代码:

<?php
    $title = the_title();
    $field['url'] = "<iframe src='http://xxx.xx/embed?t='" . echo $title . "width='640' height='360' allowscriptaccess='always' allowfullscreen='true' scrolling='no' frameborder='0'></iframe>;"
    ?>  

我需要. echo $title .,但它不起作用,我的网站甚至没有加载。那么还有其他可能回应变量$title吗?谢谢

2 个答案:

答案 0 :(得分:-1)

有一个名为sprintf

的强大功能
$title = the_title();
$field['url'] = sprintf('<iframe src="http://xxx.xx/embed?t=%s" width="640" height="360" allowscriptaccess="always" allowfullscreen="true" scrolling="no" frameborder="0"></iframe>;"', $title);

答案 1 :(得分:-1)

尝试删除回声并移动;在引号之外

<?php
$title = the_title();
$field['url'] = "<iframe src='http://xxx.xx/embed?t='" . $title . "width='640' height='360' allowscriptaccess='always' allowfullscreen='true' scrolling='no' frameborder='0'></iframe>";
?>