Time of Update: 2016-07-25
本文介紹下,有關php數組之取當前數組值的方法,有需要的朋友參考下。在php數組的操作中,可以用current()函數返回數組中當前指標所在位置的數組值。其形式如下:mixed current(array array) 例子,擷取數組值:"red", "banana"=>"yellow"); while ($fruit = current($fruits)) { printf("%s ", $fruit); next($fruits); } // by bbs.it-home.org/
Time of Update: 2016-07-25
本文介紹下,用php判斷上傳檔案大小的一段代碼,有需要的朋友參考下。代碼如下:120 || $arr[2]>60){echo "";exit(); } switch ($type) {case 'image/pjpeg' : $ok = 1; break;case 'image/jpeg' : $ok = 1; break;case 'image/gif' : $ok = 1; break; //case
Time of Update: 2016-07-25
本文介紹下,從php數組頭部刪除元素值的方法,有需要的朋友參考下。本節介紹從php數組頭刪除值的方法,可以用php數組函數array_shift()來實現,該函數刪除並返回數組中找到的元素。其結果是,如果使用的是數值健,則所有相應的值都會下移,而使用關聯鍵的數組不受影響。其形式為:mixed array_shift(array array)
Time of Update: 2016-07-25
//system('dir');// exec ('dir');// passthru ('dir');// echo
Time of Update: 2016-07-25
本文介紹下,有關php數組中擷取當前數組的鍵與值的方法,有需要的朋友參考下。在php數組函數中,each()函數返回input_array的當前鍵/值對,並將指標推進一個位置。形式如下:array each(array array) 返回的數組包含四個鍵,鍵0和key包含鍵名,而鍵1和value包含相應的資料。如果執行each()前指標位於數組末尾,則返回false。例如: apple [value] => apple [0] => 0 [key] => 0 ) ?>each() 經常和
Time of Update: 2016-07-25
本文介紹下,php中用於跳出迴圈break,以及跳過某層迴圈continue的具體用法,有需要的朋友參考下。本文帶領大家瞭解break和continue的使用,及它們在迴圈語句中的作用。1、break (int); 語句//break的作用為退出迴圈體,當break後面加上數字時,表示退出第幾層的迴圈。多用在while、do…while、for、foreach、switch語句中。例子:如果給break後面加數字時,迴圈語句的執行過程則有所改變。例子:代碼說明:$i=1
Time of Update: 2016-07-25
本文介紹下,php數組操作之在數組尾添加元素的方法,有需要的朋友參考下。在數組尾添加元素,用到php數組操作函數array_push。array_push()函數傳回值是int型,是壓入資料後數組中元素的個數,可以為此函數傳遞多個變數作為參數,同時向數組壓入多個變數。其形式為:(array array,mixed variable [,mixed variable...]) 例子,在$fruits數組中又添加了兩個水果:
Time of Update: 2016-07-25
本文介紹下,在php編程中,取數組中指定長度的資料的方法,有需要的朋友參考下。在php程式中,減少查詢的次數,也是一個提高網站整體效能的辦法。將滿足基本條件的資料全部查詢出來:accessCourse('ID DESC', 1);//查詢出所以滿足基本條件的資料,狀態正常...$list = Json_decode($list_json, true);//因為查詢出來的是json格式這裡將其轉換成array格式 //熱門課程$toplist = array_sort($list, 'NUM',
Time of Update: 2016-07-25
本文介紹下,php數組操作函數之array_values()函數用法,有需要的朋友參考下。在php數組函數中,array_values()函數返回一個數組中的所有值,並自動為返回的數組提供數值索引。其形式如下:array array_values(array array) 例子,擷取$fruits中找到的各元素的值: red [1] => yellow [2] => green )
Time of Update: 2016-07-25
本文介紹下,有關php數組求差集的方法,有需要的朋友參考下。在php中,求數組的差集。需要用到數組的差集合函式:array_diff()。php數組函數array_diff(),返回出現在第一個數組中但其他輸入數組中沒有的值。這個功能與array_intersect()相反。array array_diff(array array1,array array2[,arrayN…]) 來看一個簡單的例子: Banana ) ?>接著介紹PHP取兩個數組的差集的方法。再來看下 array_diff(
Time of Update: 2016-07-25
本文介紹下,php實現的一個ftp操作類,可以實現檔案的上傳、下載、移動與建立等功能,有需要的朋友參考下。1,php操作ftp的用法2,FTP上傳類conn_id = @ftp_connect($FTP_HOST,$FTP_PORT) or die("FTP伺服器串連失敗");@ftp_login($this->conn_id,$FTP_USER,$FTP_PASS) or die("FTP伺服器登陸失敗");@ftp_pasv($this->conn_id,1); // 開啟被動類比}/***
Time of Update: 2016-07-25
$conn = new Com("ADODB.Connection"); //執行個體化一個Connection對象$connstr = "provider=sqloledb;datasource=.;uid=使用者名稱;pwd=密碼;database=資料庫;";$conn->Open($connstr);$rs = new Com("ADODB.Recordset"); //執行個體化一個Recordcount對象/*使用執行個體*/$rs->Open('select * from
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
/** 功能:對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
/*** 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
$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
請上傳附件: 複製代碼提示:可以通過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