php中的双引号与单引号具体用法

“” 在双引号里面变量会通过编译器解释,然后再输出。‘ ‘单引号里的变量编译器不会进行解释,直接输出。看完下面这个例子你就明白了。

例如:
$sHome=’php开发者之家 http://www.086php.com’;
echo $sHome //结果是:php开发者之家 http://www.086php.com
echo ‘$sHome’ //结果是:$sHome
echo “$sHome” //结果是:php开发者之家 http://www.086php.com

php中的双引号跟单引号特别用在MYSQL语句的时候,双引号和单引号的用法让新手不知所措,在这里,举个例子,来进行说明。

假设查询条件中使用的是常量,例如:

select * from abc_table where user_name=’abc’;

SQL语句可以写成:

sSQL = “select * from abc_table where user _name= ‘abc’” ;

假设查询条件中使用的是变量,例如:

$user_name = $_REQUEST['user_name']; //字符串变量

$user=array (“name”=> $_REQUEST['user_name‘,"age"=>$_REQUEST['age'];//数组变量

SQL语句就可以写成:

sSQL = “select * from abc_table where user_name = ‘ ” . $user_name . ” ‘ “;

sSQL = “select * from abc_table where user_name = ‘ ” . $user["name"] . ” ‘ “;

对比一下:

sSQL=”select * from abc_table where user_name = ‘ abc ‘ ” ;

sSQL=”select * from abc_table where user_name =’ ” . $user _name . ” ‘ “;

sSQL=”select * from abc_table where user_name =’ ” . $user["name"] . ” ‘ “;

sSQL可以分解为以下3个部分:
1:”select * from table where user_name = ‘ ” //固定SQL语句
2:$user //变量
3:” ‘ ”
1,2,3部分字符串之间用”.” 来连接

php中的双引号与单引号具体用法》上有 1 条评论

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>