Time of Update: 2017-01-13
//cookie處理function dsetcookie($var, $value, $life = 0, $prefix = 1) { global $cookiedomain, $cookiepath, $addtime, $_server; setcookie($var, $value,$life ? $addtime + $life : 0, $cookiepath,$cookiedomain, $_server['server_port'] == 443 ? 1
Time of Update: 2017-01-13
遞迴函式為自調用函數,在函數體內直接或間接自己調用自己,但需要設定自調用的條件,若滿足條件,則調用函數本身,若不滿足則終止本函數的自調用,然後把目前流程的主控權交回給上一層函數來執行,可能這樣給大家講解,還是很難明白,直接上例子function test ($n){echo $n.” “;if($n>0){test($n-1);}else{echo “<?>”;}echo $n.” ”
Time of Update: 2017-01-13
使用者提交表單時可能因為網速的原因,或者網頁被惡意重新整理,致使同一條記錄重複插入到資料庫中,這是一個比較棘手的問題。我們可以從用戶端和伺服器端一起著手,設法避免同一表單的重複提交。1.使用用戶端指令碼<form method="post" name="register" action="test.php" enctype="multipart/form-data">
Time of Update: 2017-01-13
我們要使用gd庫就必須先開啟gd庫,具體如下Windows下開啟PHP的GD庫支援找到php.ini,開啟內容,找到:;extension=php_gd2.dll把最前面的分號“;”去掉,再儲存即可,如果本來就沒有分號,那就是已經開啟了。具體可以參考下文:http://www.111cn.net/phper/php/48352.htm一:添加文字浮水印 使用方法require
Time of Update: 2017-01-13
php架構 Yaf整合zendframework2, zf2的orm 可以作為獨立模組用到yaf中,而且zf2 composer service manger cacheStorage 都可以整合到yaf中。一:public\index.php
Time of Update: 2017-01-13
高德地圖和百度地圖座標轉換php程式 代碼如下複製代碼 <?php //GCJ-02(火星,高德) 座標轉換成 BD-09(百度) 座標 //@param bd_lon 百度經度 //@param bd_lat 百度緯度 function bd_encrypt($gg_lon,$gg_lat)
Time of Update: 2017-01-13
php中str_split函數不支援中文分割,我們可以利用mb_xx函數實現/** * Convert a string to an array * @param string $str * @param number $split_length * @return multitype:string */function mb_str_split($str,$split_length=1,$charset="UTF-8"){&
Time of Update: 2017-01-13
原理在於產生一個隨機字串放在session裡。提交表單後來驗證這個字串。可以做到防止他人自己寫form來欺騙提交,重複提交或者雙擊提交。Token.php<?php /* * Created on 2013-3-25 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code
Time of Update: 2017-01-13
亂碼情況寫了一段匯出 CSV 檔案的代碼,可以正常輸出使用 CSV 和 TXT 程式開啟檔案是正常的,但是使用 Excel 開啟檔案就出現了中文亂碼的問題(這就奇怪了, 為什麼在 Excel 中會亂碼呢?)通過查看編碼發現,匯出的 CSV 檔案是 UTF-8 無BOM編碼格式,而我們通常使用 UTF-8 編碼格式 都是有 BOM 的。嘗試著添加了 BOM 之後,中文亂碼的問題有解決了。添加 BOM 到 CSV 檔案中範例程式碼:$file = fopen($export_file_path, '
Time of Update: 2017-01-13
php中在做檔案下載的時候,其中要加上這麼一些header資訊: header("Content-type: application/octet-stream"); header("Accept-Ranges: bytes"); header("Accept-Length:".$fileSize); header("Content-Disposition: attachment;
Time of Update: 2017-01-13
/* *網站防ip攻擊代碼(anti-ip attack code website)2010-11-20,ver2.0 *mydalle.com anti-refresh mechanism *design by www.111cn.net*/<?php //查詢禁止ip $ip =$_server['remote_addr']; $fileht=".htaccess2";
Time of Update: 2017-01-13
以前有用過dedecms分詞功能,經過測試還是不理想,後來經過一些處理得到的結果還是可以接受的,今天我再看到這款分詞法,拿出來給大家看看。<?php教程 class NLP{ private static $cmd_path; // 不以'/'結尾 static function set_cmd_path($path){ self::$cmd_path = $path; } private function cmd($str){ $descriptorspec = array( 0
Time of Update: 2017-01-13
static inline ulong zend_inline_hash_func(const char *arKey, uint nKeyLength) { register ulong hash = 5381; //此處初始值的設定有什麼玄機嗎? /* variant with the hash unrolled eight times */ for (; nKeyLength >= 8; nKeyLength -= 8) { //這種step=8的方式是為何? hash
Time of Update: 2017-01-13
memcache的官方首頁:php教程.net/package/memcache">http://pecl.php.net/package/memcachememcached的官方首頁:http://pecl.php.net/package/memcached以下是我安裝Memcached版本的PHP模組的過程記錄:wget http://download.tangent.org/libmemcached-0.48.tar.gztar zxf
Time of Update: 2017-01-13
檔案上傳我們需要用到HTML裡面表單的type=file類型,及其enctype屬性。這是我們大家必須要用的。當然了PHP函數庫當中的FILE函數庫,字串類型函數庫,目錄函式庫及$_FILES[]的使用是我們必須要用到的。 也許每一個網站都可能會對上傳檔案有許多的限制,這些限制會包括
Time of Update: 2017-01-13
/**功能:對URL進行編碼*參數說明:$web_url 網站URL,不包含"http://",例如111cn.net*來源:http://111cn.net*/ 代碼如下複製代碼
Time of Update: 2017-01-13
產生zip檔案用法一: 代碼如下複製代碼 < ?phpinclude_once('pclzip.lib.php');$archive = new PclZip('archive.zip');$v_list = $archive->create('file.txt,data/text.txt,folder');if ($v_list == 0) {die("Error : ".$archive->errorInfo(true))
Time of Update: 2017-01-13
代碼如下複製代碼 <? //+------------------------+ //| pie3dfun.PHP//公用函數 | //+------------------------+ define("ANGLE_STEP", 5); //定義畫橢圓弧時的角度步長 function draw_getdarkcolor($img,$clr) //求$clr對應的暗色 { $rgb = imagecolorsforindex($img,$clr);
Time of Update: 2017-01-13
代碼如下複製代碼 <?phpclass Finder{ private $key; private $result; private $previewLen = 50; private $file_type = array('html','php','htm','txt'); function __construct($key){ $this->key =
Time of Update: 2017-01-13
PHP程式有時候需要定時執行,使用Linux的Crontab執行PHP指令碼,完成PHP計劃任務。譬如,微博上用得很多的一款APP應用——皮皮時光機,就是實現定時發送內容的功能。當然PHP中也有ignore_user_abort函數。但這兩種方法都不太可靠,不穩定。我們可以藉助Linux的Crontab工具來穩定可靠地觸發PHP執行任務。下面介紹Crontab的兩種方法。一、在Crontab中使用PHP執行指令碼就像在Crontab中調用普通的shell指令碼一樣,使用P