PHP-回声内的回声 [英] PHP - echo inside an echo

查看:96
本文介绍了PHP-回声内的回声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP if / else语句。这是我要在其他情况下回显的代码。

I have a PHP if/else statement. This is the code I'm trying to echo under an else condition.

<?php $locked = ForumData::is_topic_locked($post->topic_id);
            if ($locked->topic_locked == 1) {echo '<td align="right"><font color="#FF0000">Topic Locked</font><td>';}
            else { 
            echo '<td align="left"><a href="'.url('Forum/create_new_post?topic_id='.$post->topic_id.'&forum_id='.$post->forum_id.'').'"><img src="<?php echo SITE_URL?>/lib/skins/flyeuro/images/forums/t_reply.gif"/></a></td>'; }
            ?>

我想回应的是这个。

<img src="<?php echo SITE_URL?>

如果我尝试...'echo SITE_URL'

If I try this... 'echo SITE_URL'

Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';'

但是这不会解析图像,如果我尝试解析其他内容,这给了我无法解决的解析错误?

But this doesn't parse the image, and if I try parsing anything else, it's giving me parsing errors, which I can't fix?

因此,我如何在另一个回显中产生回显?

How can I therefore produce an echo inside another echo?

推荐答案

为什么再次打开<?php 标签,您已经在回显了

why did you open a <?php tag again, you are already in echo line?

echo '<td align="left"><a href="'.url('Forum/create_new_post?topic_id='.$post->topic_id.'&forum_id='.$post->forum_id.'').'"><img src="'.SITE_URL.'/lib/skins/flyeuro/images/forums/t_reply.gif"/></a></td>';

,什么是 SITE_URL ? s是一个变量,您忘了放 $ 吗?

and what is SITE_URL? Is that a variable, did you forget to put $?

echo输出您作为参数给出的字符串,

echo prints out the string that you gave as parameter,

echo "foo";

@ hakre 提到了用于连接字符串

$var = "foo"."bar";  //foobar

因此您可以在回显行中使用它,

So you can use it in echo line,

$var = "foo"."bar";  //foobar
echo "foo "."bar ".$var // foo bar foobar

而且定义为字符串的天气变量并不重要。这将是一个常量变量

And It's not important weather variable defined as a string. It would be a constant variable.

define('SITE_URL', 'localhost:8080/phpvms'); 
echo "my website URL is ".SITE_URL; //my website URL is localhost:8080/phpvms

这篇关于PHP-回声内的回声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆