php常用技巧
如何判断ip地址合法性
if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";
email的正则判断
eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);
检测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";
?>
文件下载头部输出如何设定
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'
用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@232.2.22.22/2222/web技术开发知识库/cn_web.rmvb");
正则匹配中文
ereg("^[".chr(0xa1)."-".chr(0xff)."]+$", $str);
批量替换文本里面的超级链接
<?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;
}
?>
相关文档:
进行文件的读和写,先打开一个文件,然后开始读或者写文件,最后再关系这个文件资源。
如,文件的读操作:
<?php
$file = fopen('your file path','r');
while(!feof($file)){ //当没有读取到文件结尾,继续循环读取操作
$line = fgets($file); //读取到一行的内容
echo $line.'<br/>';
}
fclose($file) ......
#apt-get install apache2
//安装apahce2
#apt-get install php5
//安装php5
#apt-get install mysql-server
//安装mysql服务端
#apt-get install mysql-myclient
//安装mysql的客户端
#apt-get install php-mysql
//安装php-mysql的连结
apache+php+mysql 环境已经搭建好了
将以下的服务重启一下
#/et ......
一、PHP函数Date()获取当前时间
代码:
<?php echo $showtime=date("Y-m-d H:i:s");?>
显示的格式: 年-月-日 小时:分钟:秒
相关参数:
a:"am"或者"pm"
A:"AM"或者"PM"
d:几日,二位数字,若不足二位则前面补零,如: "01"至"31"
D:星期几,三个英文字母,如: "Fri"
F:月份,英文全名,如: "Jan ......
随 着网站访问量的加大,每次从数据库读取都是以效率作为代价的,很多用ACCESS作数据库的更会深有体会,静态页加在搜索时,也会被优先考虑。互联网上流 行的做法是将数据源代码写入数据库再从数据库读取生成静态面,这样无形间就加大了数据库。将现有的ASP页直接生成静态页,将会节省很多。
下面的例子是将、index.asp?i ......
$_SERVER['PHP_SELF']
#当前正在执行脚本的文件名,与 document root相关。
$_SERVER['argv']
#传递给该脚本的参数。
$_SERVER['argc']
#包含传递给程序的命令行参数的个数(如果运行在命令行模式)。
$_SERVER['GATEWAY_INTERFACE']
#服务器使用的 CGI 规范的版本。例如,“CGI/1.1”。
$_SER ......