php字符串比较,是用单引号好,还是双引号好
对于你这种情况,其实单双引号都一样。。。
如果是引号里面有变量,就另当别论了,以下例子不是我写的,是引用别人的~~
如
$name
=
'hello';
echo
"the
$name";
会输出
the
hello
而如果是单引号
$name
=
'hello';
echo
'the
$name';
会输出
the
$name
另外你的代码有错误,$_POST[username]
username应该加引号,还是那句话,单双引号都可以
php字符串中的双引号与单引号区别
php 单引号和双引号的区别:
双引号串中的内容可以被解释而且替换,而单引号串中的内容总被认为是普通字符。
例如:
$foo = 2; echo "foo is $foo"; // 打印结果: foo is 2 echo 'foo is $foo'; // 打印结果: foo is $foo echo "foo is $foo\n"; // 打印结果: foo is 2 (同时换行) echo 'foo is $foo\n'; // 打印结果: foo is $foo\n $foo = 2; echo "foo is $foo"; // 打印结果: foo is 2 echo 'foo is $foo'; // 打印结果: foo is $foo echo "foo is $foo\n"; // 打印结果: foo is 2 (同时换行) echo 'foo is $foo\n'; // 打印结果: foo is $foo\n
在单引号串中甚至反斜杠也失去了他的扩展含义(除了插入反斜杠\\和插入单引号\')。所以,当你想在字串中进行变量代换和包 含\n(换行符)等转义序列时,你应该使用双引号。单引号串可以用在其他任何地方,脚本中使用单引号串处理速度会更快些。