您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 本溪分类信息网,免费分类信息发布

PHP常用技巧汇总

2024/3/31 5:11:40发布15次查看
本文为大家分享了多个php常用技巧,供大家参考,具体内容如下 1、php文件读取函式 //文件读取函式function php_read($file_name) {$fd=fopen($file_name,r);while($bufline=fgets($fd, 4096)){$buf.=$bufline;}fclose($fd);return $buf;} 2、文件写入函式 //
本文为大家分享了多个php常用技巧,供大家参考,具体内容如下
1、php文件读取函式
//文件读取函式function php_read($file_name) {$fd=fopen($file_name,r);while($bufline=fgets($fd, 4096)){$buf.=$bufline;}fclose($fd);return $buf;}?>
2、文件写入函式
//文件写入函式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;}?>
3、静态页面生成函式
//静态页面生成函式function phptohtm($filefrom,$fileto,$u2u=1){if($u2u==1){$data=php_read($filefrom);}else{$data=$filefrom;}php_write($fileto,$data);return true;}?>
4、指定条件信息数量检索函式
//指定条件信息数量检索函式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;}?>
5、目录删除函式
//目录删除函式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 “;}?>
6、目录名称合法性检测函式
//目录名称合法性检测function isen($str){$ret=”;for($i=0;$i $p=ord(substr($str,$i,1));if(($p57 & $p90 & $p122){nerror(“不符合规范!”);}$ret.=chr($p);}return $ret;}?>
7、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) 1) { $splitstr=”【 << “; }else $splitstr=”【 > 】”;return($where);}?>
php关于分页函式的使用说明
8、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 <1024){$filesize=”(string)$uploadfile_size” . “字节”;}elseif($uploadfile_size —-
2、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'
3、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”);
4、php正则匹配中文
ereg(“^[.chr(0xa1).-.chr(0xff).]+$”, $str);
5、批量替换文本里面的超级链接
function urlparse($str = ”){if (” == $str) return $str;$types = array(“http”, “ftp”, “https”);$replace = <<”.htmlentities('1′).htmlentities('2′).”eophp;$ret = $str;while(list(,$type) = each($types)){$ret = preg_replace(“|($type://)([^s]*)|ie “, $replace, $ret);}return $ret;}
以上就是本文的全部内容,很常用的php技巧送给大家,希望大家喜欢。
下面是为大家分享的专题内容,内容很全面,查看《php常用技巧汇总》。
本溪分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录