无为清净楼资源网 Design By www.qnjia.com
①转义的字符不同
单引号和双引号中都可以使用转义字符(\),但只能转义在单引号中引起来的单引号和转义转义符本身。如果用双引号(“”)括起字符串,PHP懂得更多特殊字符串的转义序列。
<"'; echo $str1,'<br />'; $str2 = "\",\\,a\r\n\tb\v\$\'"; echo $str2,'<br />'; "htmlcode"><"I am $age years old"; echo $str1,'<br />'; // I am $age years old echo $str2,'<br />'; // I am 20 years old; "htmlcode">//使用单引号 echo ' this \n is \r the blog \t of \\ zhoumanhe \\'; //上面使用单引号输出的值是 this \n is \r the blog \t of \ zhoumanhe \ echo ' '; echo " "; //使用双引号 echo "this \n is \r the blog \t of \\ zhoumanhe \\"; //上面使用双引号输出的值是 this is the blog of \ zhoumanhe \使用sql
假设查询条件中使用的是常量,例如:
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"] . ” ‘ “;SQLstr可以分解为以下3个部分:
1:”select * from table where user_name = ‘ ” //固定SQL语句 2:$user //变量 3:” ‘ ”附:大家也看到了 echo '<br/>'; html中的标签在单引号和双引号中都有效。
总结一下PHP引号使用原则
1.字符串的值用引号
2.PHP中尽量用单引号,HTML代码全部用双引号
3.在包含变量的时候,用双引号可以简化操作
4.复杂的情况下用大括号包起来
PHP引号还有一个用处就是,有的时候需要用php生成文本文件,换行符n需要用双引号才能好使,单引号则会直接把n当成字符输出。
使用总结:在字符串里面不需要加入 变量 或者 单引号(')和反斜杠(\) 时,尽量用单引号引字符串,因为省去了双引号检查处理转义和解析变量上面的时间。能用单引号尽量用单引号。
标签:
PHP,单引号,双引号,区别
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 黑鸭子.2005-《发烧DSD》柏菲[WAV分轨]
- 群星.1990-电影看板·人间道【宝丽金】【WAV+CUE】
- 周殷廷.2024-TO.WHOM.IT.MAY.CONCERN【环球】【FLAC分轨】
- 草蜢.1997-三人世界精选17首【宝丽金】【WAV+CUE】
- 【古琴音乐】管平湖《广陵散》2004[FLAC+CUE]
- 【中国民乐】《少数民族器乐·苗岭的早晨》2004[WAV+CUE]
- 【中国音乐】盛中国《新疆之春》2004[FLAC+CUE]
- 群星《音你而来 第8期》[320K/MP3][44.64MB]
- 群星《音你而来 第8期》[FLAC/分轨][121.21MB]
- 群星《十二女声Ⅲ》[WAV/CUE/分轨][626.4MB]
- 陈百强.1993-离不开...纪念歌集2CD【华纳】【WAV+CUE】
- 于台烟.2003-爱自己【乾坤唱片】【WAV+CUE】
- 群星.2024-我们永远是我们电影原声带【乐禾发文化】【FLAC分轨】
- 【中国民乐】张维良《秋江夜泊》2004[FLAC+CUE]
- 明达年度发烧碟MasterSuperiorAudiophile2011[DSF]