庸医

Whatever comes our way,whatever battle we have raging inside us,we always have a choice. My friend Harry taught me that.He chose to be the best of himself.It's the choices that make us who we are and we can always choose to do what's right.

导航

PHP学习笔记之一:单引号与双引号

在PHP中,理解单引号和双引号有什么区别是重要的!
封闭在单引号内的值将按照字面意义进行处理,而封闭在双引号内的值将被解释。换句话说,把变量和特殊字符放在双引号内将导致打印它们表示的值,而不是它们的字面值。
例如:
设定 $name = 'python';
下面四种代码情况
1. echo "my name is $name.";     //结果:my name is python.
2. echo 'my name is $name.';      //结果:my name is $name.
3. echo "\$my name is $name.";  //结果:$my name is python.

4. echo '\$my name is $name.';   //结果:$my name is $name.

所以一般情况下,在使用echo输出文本的时候,单引号通过和连接符号.的配合来完成所需效果,双引号直接可以包括所需输出文本,里面常含有变量。

posted on 2008-12-11 11:17  庸医  阅读(126)  评论(0编辑  收藏  举报