html5中双引号和单引号的区别

html5中双引号和单引号的区别:
1、单引号和双引号都可以作为字符串的开始符和关闭符,并且只能‍同一种单或者双引号来定义开始和结束;单引号之间的字符都被认为是字符,即使是转义符\和变量符KaTeX parse error: Expected 'EOF', got '\’' at position 6: ,例外的是\̲’̲标识单引号。 2.双引号之间的…,\,{都保留了php赋予的特殊含义。
3." “双引号里面的字段会经过编译器解释,然后再当作HTML代码输出;而’ ‘单引号里面的不进行解释,直接输加粗样式出。
例如:
$abc=‘my name is tome’;
echo a b c / / : m y n a m e i s t o m e c h o abc //结果是:my name is tom echo ' abc’ //结果是: a b c e c h o " 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”=> R E Q U E S T [ u s e r n a m e , " a g e " = > _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 =’ " . u s e r [ " n a m e " ] . " " ; S Q L s t r 3 : 1 " s e l e c t f r o m t a b l e w h e r e u s e r n a m e = " / / S Q L 2 user["name"] . " ' "; SQLstr可以分解为以下3个部分: 1:"select * from table where user_name = ' " //固定SQL语句 2: user //变量
3:” ’ "
1,2,3部分字符串之间用”.” 来连接

转自:https://zhidao.baidu.com/question/755920254033209684.html

猜你喜欢

转载自blog.csdn.net/weixin_44098197/article/details/89961587