Time of Update: 2016-07-29
複製代碼 代碼如下:function cleanGlobal($global_array, $arg, $specialchars = true, $default = null) { if(key_exists($arg, $global_array) && $global_array[$arg] != null && $global_array[$arg] != "") { if($specialchars) {
Time of Update: 2016-07-29
ange($low, $high),range($low, $high, $step);//建立順序值的數組如:range(1,4)為(1,2,3,4)又如range('a','z') each($array)按順序返回數組的當前元素,並且將下一個元素設定為當前元素; reset($array)將數組當前元素重新設定到數組開始處 list()可以用來將一個數組分解為一系列的值,如 list($a,$b)=each($array) shuffle($array),array_rand($arg,
Time of Update: 2016-07-29
PHP的數組,說白了,就是關聯資料每一條數組都是以[索引,值]的形式儲存的。其中索引預設是以0開始的數字。在未指定索引時,PHP會從0開始自動產生索引。當指定一個索引,PHP會從你指定索引最大正整數的下一個整數開始。如果你指定的是小數,PHP會取整數部分做為索引。 另外說說數組其它一些小東西: array()可以聲明一個空數組; array[] = $value 在數組存在時,追加一個資料;在數組不存時,產生一個數組,並追加資料。 array[$index] = $value 在數組存在時,
Time of Update: 2016-07-29
1. 訪問單個字元在PHP中,可以把字串當成一個字元的數組,可以直接用數組的存取方法來訪問字串。如$str[0]。在這裡要注意的是,如果字元是ASCII碼以外時,訪問會有問題。因為這種訪問只能取得一個位元組。 2. 刪除空白字元在PHP中,可以用trim(), ltrim(), rtrim()三個函數來刪除字串開頭或結尾的空白字元。其中,trim()用於刪除字元前後的空白字元;ltrim()用於刪除字元左側的空白字元;rtrim()用於刪除字元右側的空白字元。在預設情況下,會刪除以下字元:空格(
Time of Update: 2016-07-29
複製代碼 代碼如下:function ImageResize($srcFile,$toW,$toH,$toFile="") { if($toFile==""){ $toFile = $srcFile; } $info = ""; $data = GetImageSize($srcFile,$info); switch ($data[2]) { case 1: if(!function_exists("imagecreatefromgif")){ echo
Time of Update: 2016-07-29
類代碼:複製代碼 代碼如下:class Router { public function getRouter($types = 1) { if ( isset($_SERVER['PATH_INFO']) ) { $query_string = substr(str_replace(array('.html','.htm', '.asp', '//'), '',$_SERVER['PATH_INFO']),1); } else { $query_string =
Time of Update: 2016-07-29
複製代碼 代碼如下:class timer { var $time_start; var $time_end; function __construct() { $this->time_start = 0; $this->time_end = 0; } function timer() { $this->__construct(); } function start() { list($usec,$sec) = explode(" ",microtime());
Time of Update: 2016-07-29
mysql_set_charset()。 這個函數是這樣用的: mysql_set_charset('utf8', $link); 成功返回 TRUE,失敗返回 FALSE。 就這麼簡單。 下面是PHP手冊原文 This is the preferred way to change the charset. Using mysql_query() to execute SET NAMES .. is not recommended.
Time of Update: 2016-07-29
迴圈建立目錄方法 這個會產生image.gif目錄 複製代碼 代碼如下:$filepath = "test/upload/2010/image.gif"; mk_dir($filepath); // 迴圈建立目錄 function mk_dir($dir, $mode = 0755) { if (is_dir($dir) || @mkdir($dir,$mode)) return true; if (!mk_dir(dirname($dir),$mode)) return false;
Time of Update: 2016-07-29
複製代碼 代碼如下:interface js{ function ys($a,$b); } class Af implements js{ function ys($a,$b){ return "加法運算......結果為:".($a+$b); } } class Jf implements js{ function ys($a,$b){ return "減法運算......結果為:".($a-$b); } } class AAf implements js{ function
Time of Update: 2016-07-29
第一個檔案login_frm.php這個是登入視窗 代碼 複製代碼 代碼如下: 第二個檔案login.php這個是處理登入複製代碼 代碼如下:if($_POST['username'] = 'admin') { setcookie('haha','gogo'); header("location:index.php"); } ?> 第三個檔案index.php再看下效果 複製代碼 代碼如下:if($_COOKIE['haha'] == 'gogogo') { echo
Time of Update: 2016-07-29
1.定義常量define("CONSTANT", "Hello world."); 常量只能包含標量資料(boolean,integer,float 和 string)。 調用常量時,只需要簡單的用名稱取得常量的值,而不能加“$”符號,如:echo CONSTANT; 注: 常量和(全域)變數在不同的名字空間中。這意味著例如 TRUE 和 $TRUE 是不同的。 2.普通變數$a = "hello"; 3.可變變數(使用兩個貨幣符號($))$$a = "world"; 兩個變數都被定義了:
Time of Update: 2016-07-29
複製代碼 代碼如下:/** * 取得根網域名稱 * * @author lonely * @create 2011-3-11 * @version 0.1 * @lastupdate lonely * @package Sl */ class Sl_RootDomain{ private static $self; private $domain=null; private $host=null; private $state_domain; private $top_domain; /** *
Time of Update: 2016-07-29
我用的方法是按key區分塊,然後在將塊賦給其他的變數,然後再進行一些操作,這樣用到了很多的for和foreach,而且代碼量也很大,所以被退回來了。 經過上面的指導,發現真的好簡單,現在與大家一同分享。 IDFIELD1FIELD2FIELD3FIELD4Key1************meat12************meat13************meat14************meat15************fruit26************fruit27********
Time of Update: 2016-07-29
如: 複製代碼 代碼如下: 然後upload.php中可以直接用 $_FILES $_POST $_GET 等函數擷取表單內容。 今天我們著重講$_FILES函數。 當用戶端提交後,我們獲得了一個$_FILES 數組 $_FILES數組內容如下: $_FILES['myFile']['name'] 用戶端檔案的原名稱。 $_FILES['myFile']['type'] 檔案的 MIME 類型,需要瀏覽器提供該資訊的支援,例如"image/gif"。
Time of Update: 2016-07-29
我們草根站長購買的虛擬機器主機往往都有檔案數量限制,大量小檔案佔用大量資源,落伍精華區也有兄弟推薦豆瓣的解決方案,但是要有主機許可權。只能另裝思路,採用php+SQLite解決問題,經過我測試,切實可行,現在推薦給大家。 現在公開代碼: 建立資料庫檔案:php1.php 複製代碼 代碼如下:$db = new SQLite3('mysqlitedb.db'); //擷取檔案2進位流 $filename = "http://www.jb51.net/logo.gif"; $handle =
Time of Update: 2016-07-29
下面列出幾個比較常用的方法: 首先介紹一下所涉及的資料表結構,四個欄位: 複製代碼 代碼如下:uid :使用者id session_id :使用者登入後系統產生的session_id,PHP可是使用session_id()函數擷取 login_time :登入時間 logout_time :登出時間 1. 用戶端定時發送請求到伺服器端。實現方法是在使用者登入後,將uid,session_id,login_time插入一條記錄,然後在用戶端js設定一個計時器,比如每10分鐘向伺服器端發送一個請求,
Time of Update: 2016-07-29
有同學問了一個問題: 複製代碼 代碼如下:for($i = 'A'; $i echo $i; } //輸出是啥? 輸出是: 複製代碼 代碼如下:ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARAS……. 為啥? 其實很簡單, PHP的手冊中也有說明, 只不過恐怕很多人不會一章一節的把手冊仔細閱讀一遍: 複製代碼 代碼如下:PHP follows Perl's convention when dealing with
Time of Update: 2016-07-29
使用說明: //載入函式 include_once('phpCodeZip.php'); //建立加密檔案(sourceDir要加密的php檔案目錄,targetDir加密後的檔案目錄) $encryption = new PhoCodeZip('sourceDir','targetDir'); //執行行加密 $encryption->zip(); phpCodeZip.php源碼下載 phpCodeZip.rar phpCodeZip.php源碼內容 複製代碼 代碼如下:/* *
Time of Update: 2016-07-29
先來說說兩種方式: 1)定義一個字串變數,裡面儲存要載入的檔案清單。然後foreach載入。複製代碼 代碼如下:$a = '/a.class.php;/Util/b.class.php;/Util/c.class.php'; $b = '/d.php;/e.class.php;/f.class.php;/g.class.php'; // 載入基本系統檔案 $kernel_require_files = explode(';', $a);//SYS_REQUIRE_LIB_FILE_LIST);