本文介绍了如何在单引号内使用单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以解释如何使此代码正常工作吗?
Can anyone explain how to make this code work?
echo '<div id="panel1-under">Welcome <?php echo "$_SESSION['username']"; ?></div>';
我尝试删除单引号(echo '<div id="panel1-under">Welcome <?php echo "$_SESSION[username]"; ?></div>';
),但是它不起作用.
I've tried removing the single quotes (echo '<div id="panel1-under">Welcome <?php echo "$_SESSION[username]"; ?></div>';
), but it doesn't work.
推荐答案
echo "<div id=\"panel1-under\">Welcome ".$_SESSION['username']."</div>";
或
echo '<div id="panel1-under">Welcome '.$_SESSION['username'].'</div>';
快速说明:
- 您不必在回显字符串("...")内重新打开标签
- 我在这里所做的是传递与 $ _ SESSION ['username'] 和" ( .运算符的作用)
-
PHP甚至足够聪明,可以检测PHP字符串中的变量并对其进行求值:
- You don't have to reopen the tags inside a echo String (" ... ")
- What I have done here is to pass the string "Welcome " concatenated to $_SESSION['username'] and "" (what the . operator does)
PHP is even smart enough to detect variables inside a PHP string and evaluate them :
$ variablename =安德鲁";
$variablename = "Andrew";
回显你好$ variablename,欢迎使用";
echo "Hello $variablename, welcome ";
=>你好,安德鲁,欢迎
=> Hello Andrew, welcome
更多信息: PHP.net-回声
这篇关于如何在单引号内使用单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!