PHP_Day01_数据类型_string

<?php
	// 单引号创建字符串
	$str0 = 'PHP XUST';
	echo $str0;
	echo '<hr>';
	
	#  单引号中的单引号需要转义
	#$phpcn = 'PHP XUST 'www.baidu.com'';
	#echo $phpcn;
	#echo '<hr>';
	
	$str0 = ' XUST \'www.baidu.com\'';
	echo $str0;
	echo '<hr>';
	
	// 双引号创建字符串与单引号不同:可以解释变量
	$str1 = "PHP";
	echo $str1;
	echo '<hr>';
	
	$str3 = "PHP {$str0}";
	echo $str3;
	echo '<hr>';
	
// 用heredoc 语法来创建字符串:适用于大量字符串的情况
// 优化的双引号
$here1 = "PHP Chinese";
$here2 = "PHP \$Official";
$heredoc = <<<LIST
<ul>
<li><a href="http://www.php.cn">{$here1}</a></li>
<li><a href="http://www.php.cn">{$here2}</a></li>
</ul>
LIST;
echo $heredoc;
#  注意:heredoc 语法中必须保持第一列,不能有空格
#  与双引号的区别,内部的双引号不需要转义,既能解析变量还能解析转义字符

// nowdoc 语法创建字符串
// 优化的单引号
$nowdoc = <<<'EOD'
<ul>
<li>This is from method of nowdoc named list_1, $here1, 'test1'</li>
<li>This is from method of nowdoc named list_2, $here2, 'test2'</li>
</ul>
EOD;
echo $nowdoc;
?>

猜你喜欢

转载自blog.csdn.net/IronMan240/article/details/83690540