Blogger Information
Blog 56
fans 3
comment 1
visits 50828
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php输出字符串——2018年4月12日
沈斌的博客
Original
514 people have browsed it

php输出字符串,单引号,双引号区别:

实例

<meta charset="utf-8">
<?php  
	header("Content-type:text/html;charset=utf-8");

	$msg="hello";
	

	//双引号解释内部变量,{}变量定界
	echo "{$msg} world";

	echo "<hr>";

	//输出" ",\转义,
	echo "\"hello world\"";
	echo "<br>";
	echo '\'hello\'';
	echo "<br>";

	echo '"hello"' ;

	echo '<hr>';
	//特殊字符
	echo '转义字符\\,\n,\t,\$';
	// \n 用<br>替换
	echo nl2br("明天下雨\n是的");

	echo "<hr>";
	//不解析变量
	echo "{\$msg} world";

	echo "<hr>";

	//heredoc,内部变量和特殊字符自动转义;直接使用双引号
$heredoc= <<< HEREDOC
{$msg} 我们热忱欢迎来自"全国"各地的\nPHP爱好者.
HEREDOC;

echo nl2br($heredoc);

//nowdoc,不解析变量和特殊字符;直接使用单引号
$nowdoc= <<< 'NOWDOC'
	{$msg} 我们'热忱欢迎'来自"全国"各地的\nPHP爱好者.
NOWDOC;
echo "<hr>";
echo $nowdoc;
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

php.png

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post