Php 回声内部的回声-它工作吗?

Php 回声内部的回声-它工作吗?,php,wordpress,Php,Wordpress,我已经很久没有做php了,所以很抱歉这个愚蠢的问题 这是我当前的代码,我正在尝试将URL保存为变量,以便将其插入回显中,但它似乎不起作用,因为没有显示任何内容: <?php ob_start(); echo get_post_meta($post->ID, 'oldurl', true); $old_url = ob_get_contents(); ob_end_clean(); ?> <?php echo do_shortcode('[fbcomments][fbco

我已经很久没有做php了,所以很抱歉这个愚蠢的问题

这是我当前的代码,我正在尝试将URL保存为变量,以便将其插入回显中,但它似乎不起作用,因为没有显示任何内容:

<?php ob_start();
echo get_post_meta($post->ID, 'oldurl', true);
$old_url = ob_get_contents();
ob_end_clean();
?>

<?php echo do_shortcode('[fbcomments][fbcomments url="$old_url" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>

你需要转换你的报价。单引号按原样打印所有内容。双引号将处理变量。此外,回声中不需要回声

<?php echo do_shortcode("[fbcomments][fbcomments url='$old_url' width='375' count='off' num='3' countmsg='wonderful comments!']"); ?>    

变量不会用单引号替换

<?php echo do_shortcode('[fbcomments][fbcomments url="' . $old_url . '" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>

单引号不允许变量解析。

例如:

$var = 'Hello';
echo 'The content of my var is : $var';
// Will output : "The content of my var is : $var"
echo "The content of my var is : $var";
// Will output : "The content of my var is : Hello"

因此,您必须使用双引号或串联运算符:

我看不出显示的代码有任何意义。如果
get_post_meta
返回一个可以回送的值,那么为什么要回送它并使用输出缓冲来捕获该输出,而不是直接使用
$foo=get_post_meta(…)
…?只需使用
url=“$old_url”
就不需要在回送中写入回送了。。例如'echo do_shortcode('fbcomments][fbcomments url=“$old_url”width=“375”count=“off”num=“3”countmsg=“精彩评论!”)`
<?php echo do_shortcode('[fbcomments][fbcomments url="' . $old_url . '" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
$var = 'Hello';
echo 'The content of my var is : $var';
// Will output : "The content of my var is : $var"
echo "The content of my var is : $var";
// Will output : "The content of my var is : Hello"