|
HTTP,MySQL,google,Apache,PHP,SEO,百度,FTP,Linux,域名注册,Server,Chrome,Amazon,浏览器,开源,淘宝,免费软件,知识产权,中国搜索,爬虫,搜索引擎,FTP Jail,vsFTPD,qihoobot,BadBot,Ports,Network,Remove Pass-phase,SSL,Installation
| 阅读上一个主题 :: 阅读下一个主题 |
| 留言 |
|
比较不错的PHP函数
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/18, 7:45 pm
|
|
|
中文截取
GBK/GB2312:
CODE:
function cutstr($string, $length) {
$strcut = '';
if(strlen($string) > $length) {
for($i = 0; $i < $length - 3; $i++) {
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
return $strcut.' ...';
} else {
return $string;
}
}
UTF-8:
CODE
function cutstr($string, $length) {
$strcut= '';
if(strlen($string) > $length) {
preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf]"
."[x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf]"
."[x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $string, $info);
for($i=0; $i $strcut .= $info[0][$i];
$j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1;
if ($j > $length - 3) {
return $strcut." ...";
}
}
return join('', $info[0]);
} else {
return $string;
}
}
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
最后进行编辑的是 Mrs LA on 2006/03/19, 6:10 pm, 总计第 3 次编辑
|
|
|
返回页首
|
|
 |
|
这个函数可以用来判断函数的存在性
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/18, 7:48 pm
|
|
|
bool function_exists ( string function_name )
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
|
|
|
返回页首
|
|
 |
|
str_replace 这个比其他的语言里面的好用多了
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/18, 7:54 pm
|
|
|
mixed str_replace ( mixed search, mixed replace, mixed subject [, int &count] )
search : the string will be replaced
replace: the new string
subject: the orginal string
说句实话,名字叫得比较奇怪
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
|
|
|
返回页首
|
|
 |
|
email 用在url里面显示
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/18, 8:00 pm
|
|
|
function emailconv($email, $tolink = 1) {
$email = str_replace(array('@', '.'), array('@', '.'), $email);
return $tolink ? '<a href="mailto: '.$email.'">'.$email.'</a>': $email;
}
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
|
|
|
返回页首
|
|
 |
|
随即函数
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/18, 8:27 pm
|
|
|
void mt_srand ( int seed )
用 seed 来给随机数发生器播种。
int mt_rand ( [int min, int max] )
产生随机数
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
|
|
|
返回页首
|
|
 |
|
Iinsensitive string comparison
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/18, 8:36 pm
|
|
|
int strcasecmp ( string str1, string str2 )
Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
|
|
|
返回页首
|
|
 |
|
变量及常量的正则表达式
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/18, 10:36 pm
|
|
|
$var_regexp = "((\$[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)([[a-zA-Z0-9_-."''[]$x7f-xff]+])*)";
$const_regexp = "([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)";
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
|
|
|
返回页首
|
|
 |
|
随机字符串
|
|
| |
|
发布人: Mrs LA
发布于: 2006/03/21, 9:12 pm
|
|
|
function gen_rand_string($hash)
{
$chars = array( 'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't', 'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
$max_chars = count($chars) - 1;
srand( (double) microtime()*1000000);
$rand_str = '';
for($i = 0; $i < 8; $i++)
{
$rand_str = ( $i == 0 ) ? $chars[rand(0, $max_chars)] : $rand_str . $chars[rand(0, $max_chars)];
}
return ( $hash ) ? md5($rand_str) : $rand_str;
}
|
_________________ 支持洛杉矶华人,点评洛杉矶华人商家
|
|
|
返回页首
|
|
 |
|
|
|
返回页首
|
|
 |
|
热门标签: HTTP(8), MySQL(8), google(8), Apache(5), PHP(4), SEO(4), 百度(3), FTP(2), Linux(2), 域名注册(2), Server(2), Chrome(1), Amazon(1), 浏览器(1), 开源(1), 淘宝(1), 免费软件(1), 知识产权(1), 中国搜索(1), 爬虫(1), 搜索引擎(1), FTP Jail(1), vsFTPD(1), qihoobot(1), BadBot(1), Ports(1), Network(1), Remove Pass-phase(1), SSL(1), Installation(1)
|
|