Time of Update: 2016-07-25
require("config.php");require_once 'Tags.php'; $sql = "SELECT tags FROM demo"; //在這裡你可以隨機或者限制一下取出的個數. $rs = $db->query($sql);while ($tags = $db->fetch_array($rs)) { $arr[] = split("\|",iconv("gb2312","utf-8",$tags['tags']));}$tags = new
Time of Update: 2016-07-25
複製代碼注意:標籤,實現檔案上傳時,必須指定為multipart/form-data。另外,注意檔案upload.html中表單選項 MAX_FILE_SIZE 的隱藏範圍,通過設定其Value(值)可以限制上傳檔案的大小。MAX_FILE_SIZE 的值只是對瀏覽器的一個建議,實際上它可以被簡單的繞過。PHP 設定中的上傳檔案最大值,是不會失效的。不過最好還是在表單中加上 MAX_FILE_SIZE,以提高上傳體驗。2,upload.php
Time of Update: 2016-07-25
本文收集了一些php中有關stream資料流的函數集,有需要的朋友,可以參考下。php stream函數集,如下:
Time of Update: 2016-07-25
本文分享一個簡單的php使用者登入代碼,通過將使用者名稱與密碼與儲存在數組中的值進行比對,檢測是否有效。有需要的朋友可以作個參考。首先,將使用者名稱與密碼儲存在數組中,當有使用者登入時,從數組中取值參與檢測,以判斷使用者名稱與密碼是否有效。登入與檢測在同一個檔案LoginFormAction中,代碼:"pass1", "name2" =>"pass2"); if ($password ==
Time of Update: 2016-07-25
本文介紹下,用php擷取漢字中首個字母的方法,編碼格式為gb2312,有需要的朋友參考下。php取得漢字中首個字母,代碼:0xB0C4,'b'=>0xB2C0,'c'=>0xB4ED,'d'=>0xB6E9,'e'=>0xB7A1,'f'=>0xB8C0,'g'=>0xB9FD,'h'=>0xBBF6,'j'=>0xBFA5,'k'=>0xC0AB,'l'=>0xC2E7,'m'=>0xC4C2,'n'=>0xC5B5,'o'=>0xC5BD,'p'=>0xC6D9,'q'=>0xC8BA,'r
Time of Update: 2016-07-25
分享一個簡單的php分頁代碼,適合初學php的朋友參考。代碼: "; // 上一頁 if ($offset>0) { $result .= " Prev "; } $pages = $allPageNums; //總頁數 $page = $curPage; //當前頁數 $page_len = 9; $page_len =
Time of Update: 2016-07-25
本文介紹下,用php讀取圖片,並輸出到瀏覽器顯示的一段代碼,有需要的朋友參考下。在php中,如果php以圖片,zip,exe等檔案輸出到瀏覽器,而前面還輸出了其他字元,則會出現亂碼。原因分析:輸出圖片前有輸出空格或其他字元造成的,此時請檢查一下輸出圖片前有沒有其他字元,如果是utf-8編碼記得儲存為無BOM的檔案。例子:imgsrc = $source; } public function img2data(){ $this->_imgfrom($this->imgsrc);
Time of Update: 2016-07-25
本文介紹下,用php擷取百度收錄情況,以及百度快照時間的一段代碼,有需要的朋友,作個參考吧。用php代碼實現查詢百度收錄情況與百度快照時間。代碼: (.*)/”; /*用以匹配快照日期的字串*/ $times = “/\d{4}-\d{1,2}-\d{1,2}/”; /*匹配快照日期的Regex,如:2011-8-4*/ $s0 = @file_get_contents($all); /*將site:www.ninthday.net的網頁置入$s0字串中*/ $s1 =
Time of Update: 2016-07-25
if($config['urlrewrite']==1)或 if($config['urlrewrite']==='1')來判斷。複製代碼說明: $a == $b;// Equal TRUE if $a is equal to $b.$a === $b;// Identical TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP
Time of Update: 2016-07-25
//for迴圈for ($i = 0; $i { echo $i; sleep(5);}複製代碼接下來,就要shell上場了,調用php檔案:sleep.php,代碼如下: #!/bin/bash#edit by bbs.it-home.orgfor i in 1 2 3 4 5do /usr/bin/php -r -q /data/website/sleep.php &done複製代碼注意:
Time of Update: 2016-07-25
$a="ABC";$b =&$a;echo $a;//這裡輸出:ABCecho $b;//這裡輸出:ABC$b="EFG";echo $a;//這裡$a的值變為EFG 所以輸出EFGecho $b;//這裡輸出EFG?>複製代碼2,函數的傳址調用傳址調用我就不多說了 下面直接給出代碼 function test(&$a){$a=$a+100;}$b=1;echo $b;//輸出1test($b);
Time of Update: 2016-07-25
PHP代碼<?php $len = 19; $text = "怎麼將新聞的很長的標題只顯示前面一些字,後面用.....來代替?"; echo strlen($text)<=$len ? $text : (substr($text,0,$len).chr(0)."...."); ?>chr(0)不是null null是什麼都沒有,而chr(0)的值是0。表示成16進位是0x00,表示成二進位是00000000
Time of Update: 2016-07-25
本文介紹下,用於擷取副檔名的一段php代碼,在php中擷取副檔名,使用pathinfo()方法比較方便。有需要的朋友參考下。在php中,可以很方便地從檔案末尾取得檔案的副檔名。使用php函數pathinfo,可以做到這一點,在使用中注意檔案的副檔名前的點號。使用pathinfo()擷取到的副檔名,是不包括點號的。以下介紹二種擷取副檔名的方法,分別如下。方法1,方法二,與方法一基本相同,不過它使用字串操作來得到副檔名,使用.號來作為分隔字元。代碼:
Time of Update: 2016-07-25
本文介紹下,用php實現的一個可以多線程下載遠程多個檔案的函數,有需要的朋友參考下。以下代碼,實現:多線程下載遠程多個檔案,如下: $v) {if (!empty($v) && preg_match("~^http~i", $v)) {$nurl[$k] = trim(str_replace(' ', "%20", $v));$curl[$k] = curl_init($nurl[$k]);curl_setopt($curl[$k], CURLOPT_IPRESOLVE,
Time of Update: 2016-07-25
本文介紹下,一個自訂的求數組差集的函數array_different,效率要好於array_diff函數。有需要的朋友參考下。php求數組差集,代碼如下: $val) {if (isset($array_2[$val])) {unset($array_1[$key]);}}return $array_1;}function runtime($mode = 0) {static $t;if (!$mode) {$t = microtime();return;}$t1 =
Time of Update: 2016-07-25
本文介紹下,php取得超連結中常值內容的一段代碼,可以從任意的連結中提取常值內容,有需要的朋友作個參考吧。本文分享的這段代碼,使用php正則從超連結中提取文本。例如,可以從Link中,擷取常值內容:Link。代碼如下:(.*)/', $url, $matches); /*** return the match ***/ return $matches[1];}/*** example usage ***/$url = 'Url Text Link Here';echo
Time of Update: 2016-07-25
分享一段CodeIgniter上傳圖片的代碼,對於研究CodeIgniter這個php架構的朋友來說,可以作個參考。用CodeIgniter的上傳類實現上傳圖片,測試中遇到一些問題,這裡分享下要注意的地方:/*注意,此處是userfile,$this->upload->do_upload(),這裡do_upload預設上傳檔案的表單名為userfile;當然也可以使用do_upload($filename),此處的$filename一定要和form_upload()裡面的字串一致.*/contr
Time of Update: 2016-07-25
分享二個不用遞迴實現的樹形數組的建構函式,有需要的朋友,作個參考。非遞迴樹形數組建構函式,代碼: $item ) {if ($item [$pid]) {if (! isset ( $t [$item [$pid]] ['parent'] [$item [$pid]] ))$t [$item [$id]] ['parent'] [$item [$pid]] = & $t [$item [$pid]];}}return $t;}/*** * 建立子節點樹形數組 * 參數 * * $ar
Time of Update: 2016-07-25
本文介紹下,在php中用於處理基準時間的一段代碼,有需要的朋友,參考下吧。Here is a little example of how to benchmark or time something with php這裡有一段php代碼,教大家如何去處理基準時間。代碼如下:';}// the end time$time_end = getmicrotime();// subtract the start time from the end time to get the time
Time of Update: 2016-07-25
header("HTTP/1.1 301 Moved Permanently");header("Location: http://www.example.com/newpage/");exit;?>複製代碼PHP 301 for IIS: header("Status: 301 Moved Permanently");header("Location: http://www.example.com/newpage/");exit;?>複製代碼更多php 301