Time of Update: 2016-07-25
這段php類可以挨個添加檔案到數組,最後將添加的檔案打包成zip /* $Id: zip.lib.php,v 1.1 2004/02/14 15:21:18 anoncvs_tusedb Exp $ */// vim: expandtab sw=4 ts=4 sts=4: /*** Zip file creation class.* Makes zip files.** Last Modification and Extension By :** Hasin Hayder*
Time of Update: 2016-07-25
php內建的rmdir,只能刪除空目錄,這個rrmdir就可以遞迴刪除目錄及目錄下的所有檔案 function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != “.” && $object != “..”) { if (filetype($dir.”/”.$object) ==
Time of Update: 2016-07-25
/** * 數字轉換為中文 * @param string|integer|float $num 目標數字 * @param integer $mode 模式[true:金額(預設),false:普通數字表示] * @param boolean $sim 使用小寫(預設) * @return string */ function number2chinese($num,$mode = true,$sim = true){
Time of Update: 2016-07-25
class database { var $host = NULL; var $username = NULL; var $password = NULL; var $databaseName = NULL; var $link = NULL; var $queries = NULL; var $errors = NULL; var $databaseExtras = NULL; function
Time of Update: 2016-07-25
這段代碼可以檢測使用者是否使用行動裝置瀏覽網頁,檢驗非常完整 $mobile_browser = '0'; if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))){ $mobile_browser++; }
Time of Update: 2016-07-25
// $low and $high have to be integers function BinarySearch( $array, $key, $low, $high ){ if( $low > $high ) // termination case { return -1; } $middle = intval( ( $low+$high )/2 ); // gets the middle of the array if ( $array[
Time of Update: 2016-07-25
/** * Redis 操作,支援 Master/Slave 的負載叢集 * * @author jackluo */ class RedisCluster{ // 是否使用 M/S 的讀寫叢集方案 private $_isUseCluster = false; // Slave 控制代碼標記 private $_sn = 0; // 伺服器串連控制代碼 private $
Time of Update: 2016-07-25
/*untested*/ class database_mssql { var $database = NULL;var $sqls = NULL; var $host = NULL;var $username = NULL;var $password = NULL;var $databaseName = NULL;var $link = NULL;var $queries = NULL;var $errors = NULL; function database_mssql($host,
Time of Update: 2016-07-25
這段代碼可以協助你判斷任意圖片的主色調,使用了簡單的統計演算法實現 $i = imagecreatefromjpeg("image.jpg"); for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF;
Time of Update: 2016-07-25
/** * 郵件發送類 * 支援發送純文字郵件和HTML格式的郵件 * @example * $config = array( * "from" => "*****", * "to" => "***", * "subject" => "test", * "body" => "test", * "username" => "***", *
Time of Update: 2016-07-25
function pageSplit($startPos, $rowsPerPage = '', $totalRows = '' ) { $numPages = $totalRows / $rowsPerPage ; $tenthPages = $rowsPerPage * 10 ; If($startPos >= $tenthPages ) {
Time of Update: 2016-07-25
這篇文章主要介紹了2個比較經典的PHP加密解密函數分享,一個是Discuz!的authcode加密函數(帶詳細分解),一個是encrypt()函數,都比較經典,需要的朋友可以參考下 項目中有時我們需要使用PHP將特定的資訊進行加密,也就是通過密碼編譯演算法產生一個加密字串,這個加密後的字串可以通過解密演算法進行解密,便於程式對解密後的資訊進行處理。 最常見的應用在使用者登入以及一些API資料交換的情境。
Time of Update: 2016-07-25
/*** * @project Bar Graph Program * @license GPL * @package * @file GrapBar.php * @date 2007-4-3 * @version 1.0 * @last modified * 定義 柱狀圖(直條圖) 類 * * 注意,使用前請確保字型路徑存在並允許訪問,如果出錯,還要檢查在php.
Time of Update: 2016-07-25
//mktime()將日期和時間轉換為unix時間戳記//time()擷取目前時間的unix時間戳記echo date("Y-m-d",mktime(0,0,0,12,31,2013))."";//執行個體:通過計算兩個unix時間戳記的差,來計算一個使用者的年齡$year = 1991;//假設使用者的出生日期是1991.07.16 $month = 07;$day = 16;$brithday =
Time of Update: 2016-07-25
//檔案的基本操作//fopen()開啟一個檔案//使用絕對路徑開啟一個檔案,選擇唯讀模式,並返回資源$handle$handle=fopen("D:/lamp/apache2/htdocs/test/file.txt","r");//訪問主目錄下的檔案,也選擇唯讀模式$handle=fopen($_SERVER['DOCUMENT_ROOT']."/test/file.txt","r");//開啟遠程檔案,使用http協議只能以讀的方式開啟$handle=fopen("http://www.w
Time of Update: 2016-07-25
//filetype()擷取檔案的類型//擷取windows下的檔案類型echo filetype("D:\\lamp\\php5\\php.ini")."";//輸出file 表示是一個普通檔案echo filetype("D:\\lamp\\php5")."";//輸出dir 表示是一個目錄//is_file()判斷給定的檔案名稱是否是一個普通檔案//is_dir()判斷給定的檔案名稱是否是一個目錄//file_exists()檢查檔案或目錄是否存在//filesize()取得檔案的大小//
Time of Update: 2016-07-25
/** * 驗證類 * * @lastmodify 2014-5-16 * @author jy625 */ class VerifyAction{ /** * 是否為空白值 */ public static function isEmpty($str){ $str = trim($str);
Time of Update: 2016-07-25
function Pinyin($_String, $_Code='gb2312'){$_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha"."|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|
Time of Update: 2016-07-25
header('HTTP/1.1 200 OK'); // ok 正常訪問header('HTTP/1.1 404 Not Found'); //通知瀏覽器 頁面不存在header('HTTP/1.1 301 Moved Permanently'); //設定地址被永久的重新導向 301header('Location: http://www.ithhc.cn/'); //跳轉到一個新的地址header('Refresh: 10; url=http://www.ithhc.cn/');
Time of Update: 2016-07-25
//檔案本身的操作 //copy()複製檔案 //unlink()刪除檔案 //ftruncate()將檔案截斷到指定的長度 //rename()重新命名檔案或目錄 if(copy("data.txt","data_bak.txt")){//複製檔案執行個體 echo "檔案複製成功"; }else{ echo "檔案複製失敗"; } if(file_exists("data_bak.txt")