- 論壇徽章:
- 0
|
1.簡(jiǎn)易判斷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]$", $email);
----
3.檢測(cè)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.關(guān)于表單刷新
問(wèn):為什么我在點(diǎn)擊瀏覽器的后退按鈕后,所有字段的信息都被清空了?
答:這是由于你在你的表單提交頁(yè)面中使用了 session_start 函數(shù)。該函數(shù)會(huì)強(qiáng)制當(dāng)前頁(yè)面不被緩存。解決辦法為,在你的 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'); //不清空表單,如同沒(méi)使用session一般
可以在session_start();前加上session_cache_limiter("private,max-age=10800");
摘自phpe.net
5.快速搞定文件下載頭部輸出
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
----
6.用header輸出ftp下載方式,并且支持?jǐn)帱c(diǎn)續(xù)傳
一個(gè)例子:
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");
7.正則匹配中文
ereg("^[".chr(0xa1)."-".chr(0xff)."]+$", $str);
8.批量替換文本里面的超級(jí)鏈接
function urlParse($str = '')
{
if ('' == $str) return $str;
$types = array("http", "ftp", "https");
$replace =
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u/3708/showart_21156.html |
|