Time of Update: 2016-07-25
/** @截取中文字串 適用於GB2312編碼 @http://bbs.it-home.org*/function FSubstr($title,$start,$len="",$magic=true){$length = 0;if($len == "") $len = strlen($title);//判斷起始為不正確位置if($start > 0){$cnum = 0;for($i=0;$i{if(ord(substr($title,$i,1)) >= 128) $cnum ++;}if(
Time of Update: 2016-07-25
display_errors = Offerror_reporting = E_ALL複製代碼通過在 php.ini 檔案中搜尋它們,可以發現這兩個變數當前的預設值。display_errors 變數的目的很明顯 —— 它告訴 PHP 是否顯示錯誤。預設值是 Off。但是,要讓開發過程更加輕鬆,請把這個值設為 On: display_errors = On複製代碼error_reporting 變數的預設值是 E_ALL。這個設定會顯示從不良編碼實踐到無害提示到出錯的所有資訊。E_ALL
Time of Update: 2016-07-25
/** @中文字串截取函數 @http://bbs.it-home.org*/function cnSubStr($string,$sublen){if($sublen>=strlen($string)){return $string;}$s="";for($i=0;$i{if(ord($string{$i})>127){$s.=$string{$i}.$string{++$i};continue;}else{$s.=$string{$i};continue;}}return $s;}//
Time of Update: 2016-07-25
$url="http://bbs.55bbs.com";$contents=@file_get_contents($url);//preg_match_all("/(.*?)/is",$contents,$content);preg_match_all("/(.*?)/is",$contents,$content);print_r($content[0]);?>複製代碼對於較為複雜點的頁面抓取,可以考慮採用curl的方法,具體可以參考如下的文章:PHP中用CURL偽造IP來源的方法php使用cu
Time of Update: 2016-07-25
$a = 'flower';echo "She received some $as";// 無效;字母s會被當成有效變數名組成元素,但是這裡的變數是$aecho "She received some ${a}s"; // 有效echo "She received some {$a}s"; // 有效;推薦的使用方法
Time of Update: 2016-07-25
class Db { var $conn; function Db($host="localhost",$user="root",$pass="root",$db="test") { if(!$this->conn=mysql_connect($host,$user,$pass)) die("can't connect to mysql sever");
Time of Update: 2016-07-25
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String');$objPHPExcel->getActiveSheet()->setCellValue('A2', 12);$objPHPExcel->getActiveSheet()->setCellValue('A3', true);$objPHPExcel->getActiveSheet()->setCellValue('C5',
Time of Update: 2016-07-25
auto_prepend_file = "c:/Program Files/include/header.php" auto_append_file = "c:/Program Files/include/footer.php"複製代碼unix中這樣設定: auto_prepend_file = "/home/username/include/header.php" auto_append_file =
Time of Update: 2016-07-25
// Xml 轉 數組, 包括根鍵,忽略空元素和屬性,尚有重大錯誤function xml_to_array( $xml ){ $reg = "/]*?>([\\x00-\\xFF]*?)/"; if(preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); $arr = array(); for($i = 0; $i {
Time of Update: 2016-07-25
驗證碼請輸入驗證碼複製代碼2、產生驗證碼 auth.php session_start(); header("Content-type:image/png"); $img_width=100; $img_height=20; srand(microtime()*100000); for($i=0;$i { $new_number.=dechex(rand(0,15)); } $_SESSION[check_auth]=$new_number;
Time of Update: 2016-07-25
//link:http://bbs.it-home.org$discuz_url = 'http://127.0.0.1/discuz/';//論壇地址$login_url = $discuz_url .'logging.php?action=login';//登入頁地址$post_fields = array();//以下兩項不需要修改$post_fields['loginfield'] = 'username';$post_fields['loginsubmit'] =
Time of Update: 2016-07-25
複製代碼方案2:使用IP庫判斷來訪IP地址優點:判斷準確。缺點:響應速度沒Javascript快。需要引用一個PHP的IP庫:/Files/tianxin2001x/ip.zip在網站頭部引用jquery進行判斷: ...複製代碼checkip.php檔案代碼: $userip=$_SERVER['REMOTE_ADDR'];//引用ip庫的檔案 把ip.zip裡的全部檔案放在lib目錄下include_once('/lib/iplimit.class.php');$iplimit =
Time of Update: 2016-07-25
$json_string='{"id":1,"name":"foo","email":"foo@foobar.com","interest":["wordpress","php"]} ';$obj=json_decode($json_string);echo $obj->name; //prints fooecho $obj->interest[1]; //prints php?>複製代碼2、解析XML 資料I)、xml檔案
Time of Update: 2016-07-25
/* @中文字元入庫亂碼的解決方案 @bbs.it-home.org*/include_once("conn.php");include_once("include.php");mysql_query("set names 'gbk'")or die("設定字元庫失敗\n");mysql_select_db($db)or die("串連資料庫失敗!\n");$exec = "select * from $table";//echo $exec;$result =
Time of Update: 2016-07-25
//顯示訪問使用者的瀏覽器資訊echo 'Browser: ' . determinebrowser($Agent) . '';//顯示訪問使用者的作業系統平台echo 'Platform: ' . determineplatform($Agent). '';//正值運算式比對解析$_SERVER['HTTP_USER_AGENT']中的字串 擷取訪問使用者的瀏覽器的資訊function determinebrowser ($Agent) {$browseragent="";
Time of Update: 2016-07-25
function get_onlineip() { $ch = curl_init('http://www.ip138.com/ip2city.asp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $a = curl_exec($ch); preg_match('/\[(.*)\]/', $a, $ip); return $ip[1];
Time of Update: 2016-07-25
/* * 參數說明 * $max_file_size : 上傳檔案大小限制, 單位BYTE * $destination_folder : 上傳檔案路徑 * $watermark : 是否附加浮水印(1為加浮水印,其他為不加浮水印); * http://bbs.it-home.org * 使用說明: * 1. 將PHP.INI檔案裡面的"extension=php_gd2.dll"一行前面的;號去掉,因為我們要用到GD庫; * 2. 將extension_dir
Time of Update: 2016-07-25
$arr1 = array(1,9,5); $arr2 = array(6,2,4); array_multisort($arr1,$arr2); print_r($arr1); // 得到的順序是1,5,9 print_r($arr2); // 得到的順序是6,4,2複製代碼我估計兩個數組的值自始至終都是對應著的:1對應6,9對應2,5對應4。 再加多一個數組看看會怎樣: $arr1 = array(1,9,5); $arr2 = array(6,2,4); $arr3 = array(3,
Time of Update: 2016-07-25
圖片上傳-bbs.it-home.org檔案上傳(只允許上傳jpg類型圖片)複製代碼2、處理頁面 upload_img.php //上傳圖片儲存地址 $uploadfile = "upfiles/".$_FILES['upfile']['name']; //縮圖儲存地址 $smallfile = "upfiles/small_".$_FILES['upfile']['name']; if($_FILES['upfile']['type'] != "image/jpeg")
Time of Update: 2016-07-25
$arr = array('100', '200', '300');複製代碼以上就代碼就建立了一個數組,並且包含3個值。PHP數組的數字索引是從0開始的。所以$arr[0]的值為100。 可以用一個簡單的 "="號把一個數組中的值複製到另一個數組中。 如果需要將按升序排列的數字儲存到一個數組中,可以使用range()函數自動建立這個數組。如以下代碼將建立一個從1到10的數字數組: $nums = range(1,10);複製代碼這個函數還有第三個參數,可以設定數字增長的步長。如: range(