单引号和双引号的区别
双引号解析变量
单引号不解析变量
单引号效率较高
$username = 'king';
echo '$username';//$username
echo "<hr/>";
echo "$username";//king
内容和界定符冲突时使用转义符
双引号解析所有的转义符
$str = 'this is a test';
//$str='this is a test of king's PHP';//单引号需要转义
$str = 'this is a test of king\'s PHP';//this is a test of king's PHP
echo $str;
echo "<br/>";
$str = "He said \"I'm Fine\" Thank you!";
echo $str;//He said "I'm Fine" Thank you!
echo "1\n2\r3\t4\$5\\678";
//1 2 3 4$5\678
查看源代码
单引号只转义反斜线和单引号
echo '1\n2\r3\t4\$5\\6\'78';
//1\n2\r3\t4\$5\6'78