您好,欢迎访问一九零五行业门户网

PHP常用技巧总结

php文件读取函式//文件读取函式function php_read($file_name) {$fd=fopen($file_name,r);while($bufline=fgets($fd, 4096)){$buf.=$bufline;}fclose($fd);return $buf;}?>文件写入函式//文件写入函式function php_write($file_name,$data,$method=”w”) {$filenum=@fopen($file_name,$method);flock($filenum,lock_ex);$file_data=fwrite($filenum,$data);fclose($filenum);return $file_data;}?>静态页面生成函式//静态页面生成函式function phptohtm($filefrom,$fileto,$u2u=1){if($u2u==1){$data=php_read($filefrom);}else{$data=$filefrom;}php_write($fileto,$data);return true;}?>指定条件信息数量检索函式//指定条件信息数量检索函式function rec_exist($table,$where){$query=”select count(*) as num from $table “.$where;$result=mysql_query($query) or die(nerror(1));$rowcount=mysql_fetch_array($result);$num=$rowcount[num];if ($num==0){return false;}return $num;}?>目录删除函式//目录删除函式function del_dir($directory){$mydir=dir($directory);while($file=$mydir->read()){if((is_dir(“$directory/$file”)) and ($file!=”.”) and ($file!=”..”)){del_dir(“$directory/$file”);}else{if(($file!=”.”) and ($file!=”..”)){unlink(“$directory/$file”);//echo “unlink $directory/$file ok “;}}}$mydir->close();rmdir($directory);//echo “rmdir $directory ok “;}?>目录名称合法性检测函式//目录名称合法性检测function isen($str){$ret=”;for($i=0;$i $p=ord(substr($str,$i,1));if(($p57 & $p90 & $p122){nerror(“不符合规范!”);}$ret.=chr($p);}return $ret;}?>php分页函数//分页函数function splitlist($halt,$lrlist,$echocnt,$paper,$table,$where,$page_id,$userid){global $splitstr,$sumcnt;if($paper==” || $sumcnt==”){$query = “select count(*) as num from $table $where”;$result = mysql_query($query);$row = mysql_fetch_array($result);$sumcnt=$row[num];if($sumcnt==0){nerror(“该版内还没有选择发布新闻 !”);}$paper=1;}$sumpaper=($sumcnt-$sumcnt%$echocnt)/$echocnt;if(($sumcnt%$echocnt)!=0) $sumpaper+=1;if($sumpaper==1 && $halt==0) return($where);$enwhere=base64_encode(base64_encode($where));if(($lrlist*2+1) = $sumpaper){$tract=$sumpaper-($lrlist*2);$sub=$sumpaper;}else{$tract=$paper-$lrlist;$sub=$paper+$lrlist;}}else{$tract=1;$sub=$sumpaper;}$uppaper=$paper-1;$downpaper=$paper+1;$startcnt=($paper-1)*$echocnt;$where.=” limit ${ startcnt },${ echocnt }”;if($tract > 1) { $splitstr=”【 > 】”;else $splitstr.=”>> 】”;return($where);}?>php关于分页函式的使用说明php图片文件上传函式//图片文件上传函式function upload_img($uploadfile,$uploadfile_name,$uploadfile_size,$uploadpath,$max_size=64){//$timelimit=60; //设置超时限制时间 缺省时间为 30秒 设置为0时为不限时//set_time_limit($timelimit);if(($uploadfile!= “none” )&&($uploadfile != “” )){$filename=$uploadpath.$uploadfile_name;if($uploadfile_size —-php文件下载头部输出如何设定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’php用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”);php正则匹配中文ereg(“^[.chr(0xa1).-.chr(0xff).]+$”, $str);批量替换文本里面的超级链接function urlparse($str = ”){if (” == $str) return $str;$types = array(“http”, “ftp”, “https”);$replace = 以上就介绍了php常用技巧总结,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。

其它类似信息

推荐信息