很有用的一些函式,你可以作為原始碼儲存,然後以後避免重複編寫。
檔案讀取函式
//檔案讀取函式
function php_read($file_name)
fclose($fd);
return $buf;
}?>
檔案寫入函式
//檔案寫入函式
function php_write($file_name,$data,$method="w")
?>
靜態頁面生成函式
//靜態頁面生成函式
function phptohtm($filefrom,$fileto,$u2u=1)else
php_write($fileto,$data);
return true;
}?>
指定條件資訊數量檢索函式
//指定條件資訊數量檢索函式
function rec_exist($table,$where)
return $num;
}?>
目錄刪除函式
//目錄刪除函式
function del_dir($directory)else}}
$mydir->close();
rmdir($directory);
//echo "rmdir $directory ok ";}
?>
目錄名稱合法性檢測函式
//目錄名稱合法性檢測
function isen($str)
$ret.=chr($p);
} return $ret;
}?>
分頁函式
//分頁函式
function splitlist($halt,$lrlist,$echocnt,$*****,$table,$where,$page_id,$userid)
$*****=1;
}$sum*****=($sumcnt-$sumcnt%$echocnt)/$echocnt;
if(($sumcnt%$echocnt)!=0) $sum*****+=1;
if($sum*****==1 && $halt==0) return($where);
$enwhere=base64_encode(base64_encode($where));
if(($lrlist*2+1) < $sum*****)else if(($*****+$lrlist) >= $sum*****)else
}else
$up*****=$*****-1;
$down*****=$*****+1;
$startcnt=($*****-1)*$echocnt;
$where.=" limit $,$";
if($tract > 1)
else $splitstr="【 << ";
for($i=$tract;$i<=$sub;$i++)
if ($sub!=$sum*****) $splitstr.=">> 】";
else $splitstr.=">> 】";
return($where);
}?>
關於分頁函式的使用說明
/*#### 檢索分頁函式 ####
int $halt - 檢索結果僅分1頁時是否(1/0)顯示頁碼條
int $lrlist - (頁碼條顯示頁碼數-1)/2
int $echocnt - 檢索時每頁顯示記錄的數量
int $***** - 頁數,預提取:$*****=$http_get_vars[*****];
varchar $table - 資料表名,預附值:$table="db.table";
varchar $where - 檢索條件,預附值:$where="where field=/'value/'";
varchar $enwhere - 將原$where進行兩次base64_encode()編碼後以get的方式提交
varchar $splitstr - 頁碼條輸出字串,執行函式後在相應的位置執行 echo $splitstr;
函式呼叫前需獲取變數 -
return (varchar $where) - 分頁後檢索語句的檢索條件
注意:本函式需呼叫出錯處理函式 nerror($error);
*/?>
檔案上傳函式
//檔案上傳函式
function upload_img($uploadfile,$uploadfile_name,$uploadfile_size,$uploadpath,$max_size=64)elseif($uploadfile_size <(1024 * $max_size))else
//if(!file_exists($filename))else
unlink($uploadfile);
}else
//set_time_limit(30); //恢復預設超時設定}}
?>
php 採集常用函式 PHP常用採集函式
獲取所有鏈結內容和位址function getallurl code 獲取所有的位址 function getimgsrc code else fnum if fnum fnum 0 return fnum 去除html標記 function text2html txt isu r n txt re...
常用PHP函式
這是一些使用頻率比較高的函式,有的來自別人的程式.1.產生隨機字串函式 function random length return hash 2.擷取一定長度的字串 注 該函式對gb2312使用有效 function wordscut string,length sss 0 for i 0 i le...
PHP常用函式
一,字串函式 1,stringaddslashes string str 內容說明 返回字串,該字串為了資料庫查詢語句等的需要在某些字元前加上了反斜線。這些字元是單引號 雙引號 反斜線 與 nul null字元 乙個使用addslashes 的例子是當你要往資料庫中輸入資料時。例如,將名字 o re...