易截截图软件、单文件、免安装、纯绿色、仅160KB

php单引号和双引号的区别

本文转自http://xfs39.javaeye.com/blog/411508 感谢作者分享
php单引号和双引号的区别



    今天,有一新学PHP的网友问了茶农一个问题:“单引号和双引号的区别和用法?”,现将答案总结了下,写成这篇小短文。
" "双引号里面的字段会经过编译器解释,然后再当作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"]
. " ' ";
SQLstr可以分解为以下3个部分:
1:"select * from table where user_name = ' " //固定SQL语句
2:$user //变量
3:" ' "
1,2,3部分字符串之间用"." 来连接


相关文档:

php二级联动菜单改动版

/*********************************************************************************************
*****************************php二级联动菜单改动版***********************************
****************************************by garcon1986*****************************************
********************* ......

《PHP 与 MySQL Web 开发》读书笔记 (一)

概述
1.PHP 是什么?
   PHP 是服务器端解释的脚本语言,它是目前最流行的 web 编程语言之一。  在一个 HTML 页面中可以嵌入PHP代码,这些代码在每次页面访问时执行。PHP 代码将在 Web 服务器中被解释并且生成 HTML或者访问者看到其他输出结果。
2.My SQL 是什么?
   My SQL 是基于 SQL 的完 ......

Windows下php和memcahe开发

memcached本地windows系统测试
用的是windows系统。
1.下载Memcache for win32
下载地址: http://jehiah.cz/projects/memcached-win32/
选择memcached 1.2.1 for Win32 binaries (Dec 23, 2006) 是exe的程序
memcached.exe -d install
memcached -d start
2.下载php_memcache.dll
下载地址: http://www.wesoho.com/ ......

how to install apache, PHP and MySQL on Linux

how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE 9.2, 9.3, 10.0 & 10.1 operating systems, but most of the steps ought to be valid for all Linux-lik ......

how to install apache, PHP and MySQL on Linux 2

how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled
with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE
9.2, 9.3, 10.0 & 10.1, but most of the steps ought to be valid for all
Linux-like operating ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号