- 論壇徽章:
- 0
|
作者:葉金榮(
![]()
),轉(zhuǎn)載請注明出處,并不得用于商業(yè)用途。
1.簡易判斷ip地址合法性
2.email的正則判斷
3.檢測ip地址和mask是否合法的例子
4.關(guān)于表單刷新
5.關(guān)于表單刷新
1.簡易判斷ip地址合法性
if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";
----
2.email的正則判斷
eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]{2,6}$", $email);
----
3.檢測ip地址和mask是否合法的例子
$ip = '192.168.0.84';
$mask = '255.255.255.0';
$network = '192.168.0';
$ip = ip2long($ip);
$mask = ip2long($mask);
$network = ip2long($network);
if( ($ip & $mask) == $network) echo "valid ip and maskn";
?>
----
4.今天解決了一個巨郁悶的問題
ipb的添加用戶頁面toadduser.php似乎會重復(fù)提交,導(dǎo)致在添加新用戶的時候總是報該用戶已經(jīng)存在...已經(jīng)郁悶了我3天了,終于搞定,大快人心!
----
5.關(guān)于表單刷新
問:為什么我在點(diǎn)擊瀏覽器的后退按鈕后,所有字段的信息都被清空了?
答:這是由于你在你的表單提交頁面中使用了 session_start 函數(shù)。該函數(shù)會強(qiáng)制當(dāng)前頁面不被緩存。解決辦法為,在你的 Session_start 函數(shù)后加入 header("Cache-control: private"); 注意在本行之前你的PHP程序不能有任何輸出。
補(bǔ)充:還有基于session的解決方法,在session_start前加上
session_cache_limiter('nocache');// 清空表單
session_cache_limiter('private'); //不清空表單,只在session生效期間
session_cache_limiter('public'); //不清空表單,如同沒使用session一般
可以在session_start();前加上 session_cache_limiter("private,max-age=10800");
摘自phpe.net
----
6.快速搞定文件下載頭部輸出
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=$file_download_name;");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
echo 'xxx'
.......2004-08-19 11:50:30
----
7.用header輸出ftp下載方式,并且支持?jǐn)帱c(diǎn)續(xù)傳
一個例子:
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header('Accept-Ranges: bytes');
header('Connection: close');
header("Content-Type: audio/mpeg");
header("Location:ftp://download:1bk3l4s3k9s2@218.30.116.103/1001/咖哩辣椒/咖喱辣椒.rmvb");
.......2004-10-08 13:26:45
8.替換所有的字符為*
$a="~!@#$%^&*./=-";
echo preg_replace("/./","*",$a);
用perl的正則替換,方便
9.正則匹配中文
ereg("^[".chr(0xa1)."-".chr(0xff)."]+$", $str);
10.批量替換文本里面的超級鏈接
'.htmlentities('\1').htmlentities('\2').''
EOPHP;
$ret = $str;
while(list(,$type) = each($types))
{
$ret = preg_replace("|($type://)([^s]*)|ie ", $replace, $ret);
}
return $ret;
}
?>
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u/82/showart_11439.html |
|