常用PHP函数
这是一些使用频率比较高的函数,有的来自别人的程序......
1.产生随机字符串函数
function random($length) {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
2.截取一定长度的字符串
注:该函数对GB2312使用有效
function wordscut($string, $length ,$sss=0) {
if(strlen($string) > $length) {
if($sss){
$length=$length - 3;
$addstr=' ...';
}
for($i = 0; $i < $length; $i++) {
if(ord($string[$i]) > 127) {
$wordscut .= $string[$i].$string[$i + 1];
$i++;
} else {
$wordscut .= $string[$i];
}
}
return $wordscut.$addstr;
}
return $string;
}
3.取得客户端IP地址
function GetIP(){
if (getenv("http_CLIENT_IP") && strcasecmp(getenv("http_CLIENT_IP"), "unknown"))
$ip = getenv("http_CLIENT_IP");
else if (getenv("http_X_FORWARDED_FOR") && strcasecmp(getenv("http_X_FORWARDED_FOR"), "unknown"))
&nbs
相关文档:
php中如何关闭notice级的错误提示
2008-09-04 15:39
1.在php.ini文件中改动error_reporting
改为:
error_reporting = E_ALL & ~E_NOTICE
如果你不能操作php.ini文件,你可以用下面的方法 ......
使用方法:
<?
Include “email.class”
$mail->setTo("a@a.com"); //收件人
$mail-> setCC("b@b.com,c@c.com"); //抄送
$mail-> setCC("d@b.com,e@c.com"); //秘密抄送
$mail->setfrom(“f@f.com”);//发件人
$mail->setSubject(“主题”) ; //主题
$ ......
tidy 是一个非常帮忙的网页代码分析和纠错的工具,能够支持多种页面编码,并且支持xhtml输出。如果我们偷懒,甚至可以将整个页面缓存,最后采用tidy处理,最后输出完美的xhtml代码。
linux下安装过程如下:
首先安装tidy ,下载tidy源代码:
cvs -d:pserver: anonymous@tidy.cvs.sourceforge.net 为防备电子邮件地址收集 ......