如何在$ output变量

时间:2015-08-24 19:03:29

标签: php wordpress variables

我需要更正此代码,我不知道为什么我的PHP每次都被注释掉:

$output = '<ul class="custom_code">
    <li class="custom_code">
    <?php echo wpfp_link(); ?>
    </li></ul>';

return $output; 

3 个答案:

答案 0 :(得分:3)

echo立即运行。它没有任何回报。因此,您的代码有效地运行,就好像它是这样写的:

echo wpfp_link();
$output = '<ul blah blah blah</ul>';
return $output;

鉴于你正在处理单词 puke ,你可能想要更像

的东西
$output = '<ul blah blah ' . get_wpfp_link() . '...</ul>';
return $output;

同样,PHP也不像你一样可以立即嵌入。此代码将无法正常工作:

<?php
echo '<?php echo 'foo' ?>';
?>

这将输出<?php echo 'foo' ?>,而不只是'foo'

答案 1 :(得分:1)

您可以将字符串与.

连接起来
$output = '<ul class="custom_code"><li class="custom_code">'.wpfp_link().'</li></ul>';

return $output; 

答案 2 :(得分:0)

不确定它是否有效,但您可以试试。

$output = '<ul class="custom_code">
 <li class="custom_code">'.wpfp_link().'
</li></ul>';
return $output;