99久久99久久精品免观看,国产精品久久久久国产精品,国产黄色录像视频,免费的黄色毛片,国产一区精品普通话对白,色妞妞成人在线观看,最新aⅴ福利在线观看免费

綠色資源網(wǎng):您身邊最放心的安全下載站! 最新軟件|熱門排行|軟件分類|軟件專題|論壇轉(zhuǎn)帖|廠商大全

綠色資源網(wǎng)

技術(shù)教程
您的位置:首頁(yè)網(wǎng)絡(luò)編程PHP編程 → PHP中常用的函數(shù)庫(kù)和一些小技巧

PHP中常用的函數(shù)庫(kù)和一些小技巧

我要評(píng)論 2009/06/20 22:01:06 來源:綠色資源網(wǎng) 編輯:編輯整理 [ ] 評(píng)論:0 點(diǎn)擊:589次

文件讀取函式

//文件讀取函式

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;

}

?>

靜態(tài)頁(yè)面生成函式

//靜態(tài)頁(yè)面生成函式

function phptohtm($filefrom,$fileto,$u2u=1){

if($u2u==1){

$data=PHP_Read($filefrom);

}else{

$data=$filefrom;

}

PHP_Write($fileto,$data);

return true;

}

?>

指定條件信息數(shù)量檢索函式

//指定條件信息數(shù)量檢索函式

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 ";

}

?>

目錄名稱合法性檢測(cè)函式

//目錄名稱合法性檢測(cè)

function isen($str){

$ret="";

for($i=0;$i $p=ord(substr($str,$i,1));

if(($p<48 & $p!=45 & $p!=46) || ($p>57 & $p<65) || ($p>90 & $p<97 & $p!=95) || $p>122){

nerror("不符合規(guī)范!");

}

$ret.=chr($p);

}

return $ret;

}

?>

分頁(yè)函式

//分頁(yè)函式

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("該版內(nèi)還沒有選擇發(fā)布新聞 !");

}

$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){

if(($paper-$LRLIST) < 2){

$tract=1;

$sub=$LRLIST*2+1;

}else if(($paper+$LRLIST) >= $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="【 << ";

for($i=$tract;$i<=$sub;$i++){

if ($i!=$paper) $splitstr.="".$i." ";

else $splitstr.="".$i." ";

}

if ($sub!=$sumpaper) $splitstr.=">> 】";

else $splitstr.=">> 】";

return($where);

}

?>

關(guān)于分頁(yè)函式的使用說明

/*

#### 檢索分頁(yè)函式 ####

Int $HALT - 檢索結(jié)果僅分1頁(yè)時(shí)是否(1/0)顯示頁(yè)碼條

Int $LRLIST - (頁(yè)碼條顯示頁(yè)碼數(shù)-1)/2

Int $ECHOCNT - 檢索時(shí)每頁(yè)顯示記錄的數(shù)量

Int $paper - 頁(yè)數(shù),預(yù)提?。?paper=$HTTP_GET_VARS[paper];

Varchar $table - 數(shù)據(jù)表名,預(yù)附值:$table="db.table";

Varchar $where - 檢索條件,預(yù)附值:$where="where field='value'";

Varchar $enwhere - 將原$where進(jìn)行兩次base64_encode()編碼后以GET的方式提交

Varchar $splitstr - 頁(yè)碼條輸出字串,執(zhí)行函式后在相應(yīng)的位置執(zhí)行 echo $splitstr;

函式調(diào)用前需獲取變量 -

$paper=$HTTP_GET_VARS[paper];

$sumcnt=$HTTP_GET_VARS[sumcnt];

$enwhere=$HTTP_GET_VARS[enwhere];

Return (Varchar $where) - 分頁(yè)后檢索語(yǔ)句的檢索條件

注意:本函式需調(diào)用出錯(cuò)處理函式 nerror($error);

*/

圖片文件上傳函式

//圖片文件上傳函式

function upload_img($UploadFile,$UploadFile_name,$UploadFile_size,$UploadPath,$max_size=64){

//$TimeLimit=60; //設(shè)置超時(shí)限制時(shí)間 缺省時(shí)間為 30秒 設(shè)置為0時(shí)為不限時(shí)

//set_time_limit($TimeLimit);

if(($UploadFile!= "none" )&&($UploadFile != "" )){

$FileName=$UploadPath.$UploadFile_name;

if($UploadFile_size <1024){

$FileSize="(string)$UploadFile_size" . "字節(jié)";

}elseif($UploadFile_size <(1024 * $max_size)){

$FileSize=number_format((double)($UploadFile_size / 1024), 1) . " KB";

}else{

nerror("文件超過限制大小!");

}

//{

//$FileSize="number_format((double)($UploadFile_size" / (1024 * 1024)), 1) . " MB";

// }

if(!file_exists($FileName)){

if(copy($UploadFile,$FileName)){

return "$UploadFile_name ($FileSize)";

}else{

nerror("文件 $UploadFile_name 上載失敗!");

}

unlink($UploadFile);

}else{

nerror("文件 $UploadFile_name 已經(jīng)存在!");

}

//set_time_limit(30); //恢復(fù)缺省超時(shí)設(shè)置

}

}

以下是一些小技巧:

如何判斷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);

檢測(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";

?>

----

文件下載頭部輸出如何設(shè)定

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下載方式,并且支持?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@232.2.22.22/2222/web技術(shù)開發(fā)知識(shí)庫(kù)/cn_web.rmvb");

正則匹配中文

ereg("^[".chr(0xa1)."-".chr(0xff)."]+$", $str);

批量替換文本里面的超級(jí)鏈接

function urlPar

關(guān)鍵詞:PHP

閱讀本文后您有什么感想? 已有 人給出評(píng)價(jià)!

  • 1 歡迎喜歡
  • 1 白癡
  • 1 拜托
  • 1 哇
  • 1 加油
  • 1 鄙視