PHP中双引号和单引号的区别一览

来源:互联网 发布:手机windows live ID 编辑:程序博客网 时间:2024/05/17 14:17
<?php
//单引号中可以使用双引号,双引号中也可以使用单引号;
$str1='this is a "demo"';
$str2="this is a 'demo'";


//单引号中不可以再使用单引号,双引号中也不可以再使用双引号;
//$str3='very 'good'!'; //错误
//$str4="it is a "good" day";//错误


//双引号可以解析变量,单引号不可以解析变量;
$int=10;
$str5="$int is a  variable";
$str6='$int is a variable';
echo $str5."<br>";//输出 10 is a variable
echo $str6."<br>";//输出 $int is a variable


//双引号中可以转译字符,如\t\r\n等;单引号中不可以转译字符,但可以转译单引号自己和转译转译字符\本身;
$str7="this is\ta\rdemo\ntest";
echo $str7."<br>";
$str8='this is\ta\rdemo\ntest';
echo $str8."<br>";//输出this is\ta\rdemo\ntest,无法转译
$str9='this is\'a\'demo \\test';
echo $str9;


?>
原创粉丝点击