最常见的一种命令在PHP echo命令。它是一种发送输出如字符串或其他数据给用户。我们仅仅通过数据回波,它会输出给用户。
注意仔细,echo命令不是函数实际上是一个语言结构。
我们详细看一下PHP echo命令下面的教程。
在PHP中使用echo输出
使用PHP echo的结构如下:
<?php
echo 'Whatever you want to show on the screen!!';
$myString = '<br />I love Tutorial Arena';
echo $myString;
echo "$myString because it shows me this!";
?>
上面的代码会给:
Whatever you want to show on the screen!!
I love Tutorial Arena
I love Tutorial Arena because it shows me this!
记住,如果你不打算输出任何变量使用echo命令你应该使用单引号附上您的输出。这是因为PHP解析双引号内的一切寻找变量输出。因此,如果你不回应一个变量,你应该使用单引号echo命令使您的脚本运行得更快。
你也可以直接呼应一个变量(不使用任何引号),上面的例子所示。
注意,我们还与变量输出HTML打破标记。这是为了确保我们的屏幕上显示在一个单独的行。毕竟,我们是用浏览器查看我们需要确保浏览器显示它如何我们想要的。
在PHP中处理报价
我们可以看到,引号使用附上无论我们与echo命令输出。所以如果我们想输出一个报价吗?我们必须使用一个转义序列。转义序列告诉PHP解释器,下一个字符是一个我们想要使用,也就是说,不是一个PHP代码的一部分。的转义序列使用PHP是反斜杠\。
<?php
echo 'That\'s all there is to it<br />';
echo 'This is how we print a backslash \\<br />';
echo 'If we use a " it does not affect the single quote pair<br />';
echo "And vice-versa ' as well<br />";
?>
结果:
That's all there is to it
This is how we print a backslash \
If we use a " it does not affect the single quote pair
And vice-versa ' as well
如果你是一个新人,PHP,接管你的时间和阅读本教程,回声在PHP中是一个重要的构造。