设为首页收藏本站
开启辅助访问

php单引号和双引号的区别及其他

您所在的位置:网站首页 linux双引号和单引号 php单引号和双引号的区别及其他

php单引号和双引号的区别及其他

#php单引号和双引号的区别及其他| 来源: 网络整理| 查看: 265

“单引号和双引号的区别和用法?”现将答案总结了下,写成这篇小短文。

 

 

 

" "

双引号里面的字段会经过编译器解释,然后再当作

HTML

代码输出。

 

 

 

' '

单引号里面的不进行解释,直接输出。

 

 

 

例如:

 

 

$abc='my name is tome'; 

 

echo $abc //

结果是

:my name is tom 

 

echo '$abc' //

结果是

:$abc 

 

echo "$abc" //

结果是

:my name is tom 

 

 

特别在使用

MYSQL

语句的时候,

双引号和单引号的用法让新手不知所措,

在这里,

举个例

子,来进行说明。

 

 

 

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

 

 

 

select 

 

 

 

 

 

 

from 

 

 

 

abc_table where user_name='abc'; 

 

 

SQL

语句可以写成

 

 

SQLstr = "select 

 

 

 

 

 

 

from abc_table where user _name= 'abc'" ; 

 

 

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

 

 

 

$user_name = $_REQUEST['user_name']; //

字符串变量

 

 

 

 

 

 

$user=array ("name"=> $_REQUEST['user_name

,"age"=>$_REQUEST['age'];//

数组变量

 

 

 

SQL

语句就可以写成:

 

 

 

SQLstr = "select 

 

 

 

 

 

 

from abc_table where user_name = ' " . $user_name . " ' "; 

 

 

SQLstr = "select * from abc_table where user_name = ' " . $user["name"] . " ' "; 

 

 

对比一下

 

 

SQLstr="select * from abc_table where user_name = ' abc ' " ; 

 

 

SQLstr="select * from abc_table where user_name =' " . $user _name . " ' "; 

 

 

SQLstr="select * from abc_table where user_name =' " . $user["name"] . " ' "; 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3