php 中的单引号 双引号 反引号的作用
字符串的写法
字符串以单、双或倒引号围住分别有不同的义意。
单引号
例如:
$str = 'An apple a day keeps the docter away.'
当字符串出现 ' 符号时,必须加上:
'I'm wing'
应改成:
'I'm wing'
才对,其中 ' 即称为跳脱字符 (escape character)。
双引号
以双引号围住的字符串 PHP 会对该字符串做 variable interpolation 的动作,亦即做变量的取代:
$name = "Wing";
echo 'Name: $name';
echo "Name: $name";
执行结果为:
Name: $name
Name: Wing
在双引号里的字符串如果有 $ (dollar sign),只要改成跳脱字元的写法即可:
$total = 12000
echo "Total: $ $total"; //输出 Total: $ 12000
在做 variable interpolation 时,变量名称是以一个以上空格做为界线,例如:
$n_file = 5;
if ($n_file == 1) {
echo "There are $n_file.";
} else {
echo "There are $n_files.";
}
当 $n_file 不为 1 时,"There are $n_files." PHP 所看到的变量为 $n_files,而不是正确的 $n_file,所以必须改成:
$n_file = 5;
if ($n_file == 1) {
echo "There are $n_file.";
} else {
echo "There are {$n_file}s.";
}
单引号内的双引号,或是双引号内的单引号都视为有效字符,不需使用跳脱字符,例如:
echo "I'm a happy bird.";
echo 'I'm a happy "bird"!';
输出结果为:
I'm a happy bird.
I'm a happy "bird"!
反引号
利用反引号可以执行 Unix 下的命令,并传回执行结果。例如:
echo `ls -l *.txt`;
表示将 ls -l *.txt 命令的执行结果输出,以反引号围住的字符串为要执行的 UNIX 指令。
相关文档:
[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; PHP attempts to find and load this configuration from a number of locations.
; The follo ......
1、首先通过代码来看看表象:
<?php
session_start();
if (empty($_SESSION['count'])) {
$_SESSION['count'] = 1;
} else {
$_SESSION['count']++;
}
var_dump($_SESSION);
var_ ......
在DOS中进行MySQL的访问可能乱码的情况有三种,
首先,要做的是检查MySQL的配置,安装的时候选择utf-8的语言环境会省去很多的麻烦
1. 检查MySQL的服务端、客户端的语言设置是否为“utf8”,不是的话手动将my.int更改过来;
2. 在PHP进行第一次mysql_query之前设置使用连接的字符集为"SET N ......
PayPal 快速、安全而又方便,是跨国交易的首选在线付款方式。现在PayPal可以和国内大部分信用卡关联,可以实现国人的跨国交易收支。
申请PayPal注册网址:https://www.paypal.com/
paypal接口与其它接口有些不同,稍微复杂一点。 其实银行接口也算是一个站点的插件。
所谓paypal ipn(Instant Payment Notification),就 ......
.$dbhost = 'localhost';
$dbuser = 'root'; //你的mysql用户名
$dbpass = '123456'; //你的mysql密码
$dbname = 'data'; //你的mysql库名
//连接本地数据库
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);
//打开数据库
mysql_select ......