欢迎光临
我们一直在努力

PHP日常实用小Tips-PHP教程,PHP应用

建站超值云服务器,限时71元/月

1.简易判断ip地址合法性
2.email的正则判断
3.检测ip地址和mask是否合法的例子
4.关于表单刷新
5.关于表单刷新

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]$", $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似乎会重复提交,导致在添加新用户的时候总是报该用户已经存在...已经郁闷了我3天了,终于搞定,大快人心!
----
5.关于表单刷新
问:为什么我在点击浏览器的后退按钮后,所有字段的信息都被清空了?

答:这是由于你在你的表单提交页面中使用了 session_start 函数。该函数会强制当前页面不被缓存。解决办法为,在你的 session_start 函数后加入 header("cache-control: private"); 注意在本行之前你的php程序不能有任何输出。

补充:还有基于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下载方式,并且支持断点续传
一个例子:
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.批量替换文本里面的超级链接
<?php
function urlparse($str = )
{
if ( == $str) return $str;

$types = array("http", "ftp", "https");

$replace = <<<eophp
<a href=".htmlentities(\1).htmlentities(\2).">.htmlentities(\1).htmlentities(\2).</a>
eophp;

$ret = $str;

while(list(,$type) = each($types))
{
$ret = preg_replace("|($type://)([^\s]*)|ie ", $replace, $ret);
}

return $ret;
}
?>
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » PHP日常实用小Tips-PHP教程,PHP应用
分享到: 更多 (0)