Time of Update: 2016-07-25
function getRealIpAddr() { if (!emptyempty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy {
Time of Update: 2016-07-25
使用下面的 PHP 片段可以即時壓縮 zip 檔案 function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; }
Time of Update: 2016-07-25
Mandrill 是一款強大的 SMTP 提供器。開發人員傾向於使用一個第三方 SMTP provider 來擷取更好的收件交付。 下面的函數中,你需要把 “Mandrill.php” 放在同一個檔案夾,作為 PHP 檔案,這樣就可以使用TA來發送郵件。 function send_email($to_email,$subject,$message1){require_once 'Mandrill.php';$apikey = 'XXXXXXXXXX'; //specify your
Time of Update: 2016-07-25
$f = file('words.txt');$words = array();foreach ($f as $w) { $words[] = preg_quote(trim($w), '/');}$text = file_get_contents('text.txt'); $start = microtime(true);$reg = '/' . implode('|', $words) . '/S'; preg_match_all($reg, $text, $m); $result =
Time of Update: 2016-07-25
支援文字浮水印、圖片浮水印支援浮水印的位置隨機或固定(九宮格)浮水印透明度設定(圖片浮水印和文字浮水印都支援)文字 浮水印的字型、顏色、大小設定圖片浮水印的背景透明 /** * 加浮水印類,支援文字圖片浮水印的透明度設定、浮水印圖片背景透明。 * 日期:2011-09-27 * 作者:www.itwhy.org * 使用: * $obj = new WaterMask($imgFileName); //執行個體化對象 * $obj->$waterType =
Time of Update: 2016-07-25
/** * 下載遠程圖片到本地 * * @param string $url 遠程檔案地址 * @param string $filename 儲存後的檔案名稱(為空白時則為隨機產生的檔案名稱,否則為原檔案名稱) * @param array $fileType 允許的檔案類型 * @param string $dirName 檔案儲存的路徑(路徑其餘部分根據時間系統自動產生) * @param int $type 遠程擷取檔案的方式 * @return json 返迴文件名、檔案的儲存路徑 *
Time of Update: 2016-07-25
PHP目錄的遍曆 //php目錄的遍曆function showDetail($dirname){$ds = opendir($dirname);while($file = readdir($ds)){$path = $dirname."/".$file;if($file != "." && $file != ".."){ //這裡是個坑if(is_dir($path)){showDetail($path);
Time of Update: 2016-07-25
$img=imagecreatetruecolor(100, 40);$red=imagecolorallocate($img, 255, 0, 0);$green=imagecolorallocate($img, 0, 255, 0);$blue=imagecolorallocate($img, 0, 0, 255);$white=imagecolorallocate($img, 255, 255, 255);$black=imagecolorallocate($img, 0, 0, 0);/
Time of Update: 2016-07-25
/** * auther soulence * 調用資料類檔案 * modify 2015/06/12 */class DBConnect{ private $dbname = null; private $pdo = null; private $persistent = false; private $statement = null; private $lastInsID = null; private static $_instance = [];
Time of Update: 2016-07-25
/** +------------------------------------------------ * 通用的樹型類 +------------------------------------------------ * @author yangyunzhou@foxmail.com +------------------------------------------------ * @date 2010年11月23日10:09:31 +------------------------
Time of Update: 2016-07-25
//擷取指定URL頁面中所有連結 function get_url_href($url){ $html = file_get_contents($url); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate('/html/body//a')
Time of Update: 2016-07-25
class PHPZip{function Zip($dir, $zipfilename){ if (@function_exists('gzcompress')) { $curdir = getcwd(); if (is_array($dir)) { $filelist = $dir; } else {
Time of Update: 2016-07-25
採用鳥哥的PHP的C擴充Yaf的執行個體案例示範 開放原始碼 見下方 [PHP]代碼 /** * 獲得上傳組件 * * @access public * @return void */ public function uploadAction() { $sid = 'AngryFox'; /** $css參數,從 http://oapi.56.com/var/oupload/ 上擷取你想要的顯示效果 */
Time of Update: 2016-07-25
...呃~添加個緩衝機制就完美了! 也不知道這樣寫比那些都是正則的模板引擎效能會不會更高點 ? [PHP]代碼 $a = array( 'a','b','c');require 'template/demo.php';//引用模板?>複製代碼 [PHP]代碼 模板檔案: 模板測試 複製代碼 [PHP]代碼 索引值: //數組的迭代//smarty:{foreach item=na from=$a key=key} 索引值:{$key}
Time of Update: 2016-07-25
des加密是對稱式加密中在互連網應用的比較多的一種加密方式,php 通過mcrypt擴充庫來支援des加密,要在Php中使用des加密,需要先安裝mcrypt擴充庫 下面是加密解密的執行個體 $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);$key = "This is a very secret key";/
Time of Update: 2016-07-25
curl雖然功能強大,但是只能偽造$_SERVER["HTTP_X_FORWARDED_FOR"],對於大多數IP地址檢測程式來說,$_SERVER["REMOTE_ADDR"]很難被偽造: 首先是client.php的代碼 01 $headers['CLIENT-IP'] = '202.103.229.40'; 02
Time of Update: 2016-07-25
十個超級有用的php程式碼片段 [PHP]代碼 1. 傳送簡訊調用 TextMagic API。// Include the TextMagic PHP librequire('textmagic-sms-api-php/TextMagicAPI.php');// Set the username and password information$username = 'myusername';$password = 'mypassword';// Create a new
Time of Update: 2016-07-25
[PHP]代碼 //blog.qita.inecho 'md5檢驗[目錄直接md5目錄名稱,檔案就md5_file整個檔案的內容]';$filename = "test.txt";if(is_dir($filename)){ $md5file = md5($filename);}else{ $md5file = md5_file($filename);}echo $md5file;//儲存原始檔案的md5值到md5file.txt檔案//file_put_contents("md5
Time of Update: 2016-07-25
他的特點:單純,接受參數,給出分頁;靈活:可以自己決定,上、下一頁的名稱(比如我想叫prev、nex t諸如此類)可以決定每頁展示的分頁數量,跨頁數提供一個封裝方法,適應不同的網頁結構,比如有的網頁我需要每個分頁包含一個li(1 ...),依次類推備忘說明:提供的示範代碼中有兩個靜態方法大家可以不必理會。這個是自己項目開發用的。Call::import,大家可以使用include代
Time of Update: 2016-07-25
[PHP]代碼 class mysql { private $db_host; //資料庫主機 private $db_user; //資料庫使用者名稱 private $db_pwd; //資料庫使用者名稱密碼 private $db_database; //資料庫名 private $conn; //資料庫連接標識; private $result; //執行query命令的結果資源標識 private $sql; //sql執行語句