Time of Update: 2016-07-25
/*** 批量過濾post,get敏感性資料* by bbs.it-home.org*/ if (get_magic_quotes_gpc()) { $_GET = stripslashes_array($_GET); $_POST = stripslashes_array($_POST); } function stripslashes_array(&$array) { while(list($key,$var) = each($array)) {
Time of Update: 2016-07-25
/*** PHP Socket POP3類* by bbs.it-home.org*/class SocketPOPClient { var $strMessage = ''; var $intErrorNum = 0; var $bolDebug = false; var $strEmail = ''; var $strPasswd = ''; var $strHost =
Time of Update: 2016-07-25
/** 功能:對URL進行編碼* 參數說明:$web_url 網站URL,不包含"http://"* site: bbs.it-home.org*/function HashURL($url){ $SEED = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer."; $Result = 0x01020345; for ($i=0; $i {
Time of Update: 2016-07-25
/** * 取得輸入目錄所包含的所有目錄和檔案 * 以關聯陣列形式返回 * edit: bbs.it-home.org */ function deepScanDir($dir) { $fileArr = array(); $dirArr = array(); $dir = rtrim($dir, '//'); if(is_dir($dir)){ $dirHandle = opendir($dir);
Time of Update: 2016-07-25
//1,串連資料庫 $conn = mysql_connect('127.0.0.1','root','root'); if(!$conn){ die("串連失敗".mysql_error); }//2,選擇資料庫 mysql_select_db("test");//3,發送動作陳述式 $sql="select * from user";//4,接收結果 $res=mysql_query($sql,$conn);//5,遍曆結果 while($row=mysql_fetch_row($res))
Time of Update: 2016-07-25
/*** phpexcel用法舉例* by bbs.it-home.org* ################*///設定PHPExcel類庫的include path set_include_path('.'. PATH_SEPARATOR . 'D:\Zeal\PHP_LIBS' . PATH_SEPARATOR . get_include_path()); /** *
Time of Update: 2016-07-25
class Person { private $name; private $age; function __construct($name, $age) { $this->name = $name; $this->age = $age; }function say() {echo "我的名字叫:".$this->name."";echo " 我的年齡是:".$this->age; }}$p1 = new Person("張三", 20);$p1_string = serialize($p1);
Time of Update: 2016-07-25
$foo=false;$foo1=true;echo "為假時輸出值為:".$foo; //沒有輸出值echo "為真時輸出值為:".$foo1; //輸出1複製代碼一些要注意的細節:當轉換為 boolean 時,以下值被認為是 FALSE :1、the 布爾值 FALSE 自身 2、the 整型值 0 (零) 3、the 浮點型值 0.0 (零) 空 字串, 以及 字串 "0" 4、不包括任何元素的數組 5、不包括任何成員變數的對象(僅PHP 4.0 適用) 6、特殊類型 NULL
Time of Update: 2016-07-25
$uptypes=array( //上傳檔案的ContentType格式 'image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-png', 'application/msword',//doc
Time of Update: 2016-07-25
$p = 6 or 0; var_dump($p);//int(6)$p = 6 || 0; var_dump($p);//bool(true)$p = 6 and 0; var_dump($p); //int(6) $p = 6 && 0; var_dump($p); //bool(false) 複製代碼因為賦值運算的優先順序比AND和OR的高,所以先賦值;比&&和||的低,所以邏輯運算子先執行,先邏輯運算,再賦值。
Time of Update: 2016-07-25
/*** 小數位四捨五入並補零* by bbs.it-home.org*/function round_pad_zero($num, $precision) { if ($precision return round($num, 0); } $r_num = round($num, $precision); $num_arr = explode('.', "$r_num"); if (count($num_arr) == 1)
Time of Update: 2016-07-25
/*** sqlite_query函數簡單樣本* by bbs.it-home.org*/ $sqldb = sqlite_open("mydatabase.db"); $results = sqlite_query($sqldb, "SELECT * FROM employee"); while (list($empid, $name) = sqlite_fetch_array($results)) { echo "Name: $name (Employee
Time of Update: 2016-07-25
請上傳附件: 複製代碼提示:可以通過php.ini中的upload_max_filesize來設定允許上傳檔案的最大值。另外,還有一個post_max_size也可以用來設定允許上傳的最大表單資料,即表單中各種資料之和,因此,也可以通過設定這個欄位來控制上傳檔案的最大值。不過要注意後者的值必須大於前者,因為前者屬於後者的一部分表單資料。
Time of Update: 2016-07-25
Header(“Location: http://bbs.it-home.org”;);exit; //在每個重新導向之後都必須加上“exit”,避免發生錯誤後,繼續執行。?>header(“refresh:3;url=http://bbs.it-home.org”);print(‘正在載入,請稍等…三秒後自動跳轉~~~’); header重新導向 就等價於替使用者在地址欄輸入url?> 複製代碼例2,禁止頁面在IE中緩衝 header('Expires: Mon, 26 Jul 1997
Time of Update: 2016-07-25
function mb_is_utf8($string) { return mb_detect_encoding($string, 'UTF-8') === 'UTF-8';//新發現 } 複製代碼方法二: function preg_is_utf8($string) { return preg_match('/^.*$/u', $string) > 0;//preg_match('/^./u', $string) }
Time of Update: 2016-07-25
//匯出數組為變數$a = 'Original';$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");extract($my_array); // bbs.it-home.orgecho "\$a = $a; \$b = $b; \$c = $c";?>複製代碼輸出結果:$a = Cat; $b = Dog; $c = Horse例2,使用全部參數: $a = 'Original';$my_array = array("a"
Time of Update: 2016-07-25
//記錄while迴圈的次數//by bbs.it-home.org $link = mysql_connect('localhost','root','pwd'); mysql_select_db('db'); $sql = "select region_id,local_name from regions where region_grade=1"; $result = mysql_query($sql); $i =0; while ($row= mysql_fetch_
Time of Update: 2016-07-25
/*** 無重複合并多個數組的元素值* by bbs.it-home.org*/function array_values_merge() { $argc = func_num_args(); if ($argc == 0) { return false; } else if ($argc == 1) { $arg1 = func_get_arg(0); if (is_array($arg1)) {
Time of Update: 2016-07-25
/*** sqlite_create_function函數樣本* edit: bbs.it-home.org*/ define("PPO",400); function my($salary){ return $salary / PPO; } $sqldb = sqlite_open("mydatabase.db"); sqlite_create_function($sqldb,"myFunction", "my", 1); $query = "select
Time of Update: 2016-07-25
/*** 短串連產生演算法 * site: bbs.it-home.org*/ class Short_Url { #字元表 public static $charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; public static function short($url) { $key =