1. 单引号和双引号区别 http://cuckoosnest.iteye.com/blog/473888
2. define常量,常量引用不要加$
set_include_path设置include目录
<?php
// Works as of PHP 4.3.0
set_include_path('/inc');
// Works in all PHP versions
ini_set('include_path', '/inc');
?>
<?php
$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
// In this example we add /usr/lib/pear to the end of the existing include_path.
?>
3. 路径相关: dirname( __FILE ) 当前文件所在目录,被include的文件中调用此方法,也是指被include的文件所在目录。
3. 字符串函数
str_replace("\\", '/', substr(dirname(__FILE__), 0, -7)); //这里的 "\\" 不能写成 '\'
substr()方法
<?php
echo substr('abcdef', 1); // bcdef
echo substr('abcdef', 1, 3); // bcd
echo substr('abcdef', 0, 4); // abcd
echo substr('abcdef', 0, 8); // abcdef
echo substr('abcdef', -1, 1); // f
// Accessing single characters in a string
// can also be achived using "curly braces"
$string = 'abcdef';
echo $string{0}; // a
echo $string{3}; // d
echo $string{strlen($string)-1}; // f
?>
引用
The strcasecmp() function compares two strings.
strcasecmp()函数的作用是:对两个字符串进行比较。
This function returns:
该函数将返回下列值:
0 - if the two strings are equal
0 – 如果字符串相等
<0 - if string1 is less than string2
<0 – 如果string1小于string2
int strpos ( string haystack, mixed needle [, int offset] ) 查找needle在haystack中的位置,
注意:如果不匹配到needle,则返回false,也有可能返回0,因此判断这个函数返回值必须用 === 符号!
4. 时间函数 microtime()
对脚本进行计时
<?php
/**
* Simple function to replicate PHP 5 behaviour
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
// Sleep for a while
usleep(100);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Did nothing in $time seconds\n";
?>
int time ( void ) 返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数。