Time of Update: 2016-07-25
$array1 = array("a" => "green", "red", "blue");$array2 = array("b" => "green", "yellow", "red");$result = array_intersect($array1, $array2);?>複製代碼上例將輸出:Array([a] => green[0] => red)2.array_intersect_assoc()在前一個函數的基礎上,返回所有數組中鍵、值均相同的索引值對。例子: $array1 =
Time of Update: 2016-07-25
/** @php截取utf-8中文字串亂碼 @link http://bbs.it-home.org*/function utf8_substr($str,$len){ for($i=0;$i { $temp_str=substr($str,0,1); if(ord($temp_str) > 127){ $i++; if($i $new_str[]=substr($str,0,3); $str=substr($str,3); }
Time of Update: 2016-07-25
function validate_email($email){$exp="^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";if(eregi($exp,$email)){ //先用Regex驗證email格式的有效性if(checkdnsrr(array_pop(explode("@",$email)),"MX")){//再用checkdnsrr驗證email的網域名稱部分的有效性 return true;}else{
Time of Update: 2016-07-25
php檔案上傳時,用 move_uploaded_file 這個函數不能移動檔案,而用copy 或者 rename 確是可以的。php檔案上傳時,用 move_uploaded_file 這個函數不能移動檔案,而用copy 或者 rename 確是可以的。文檔上說的比較模糊,就是 move_uploaded_file 這個函數,加了一步檢查,檢查這個檔案是否是有 HTTP POST 上傳的。後來,終於原始碼裡面看到 把檔案名稱和php 配置中的 upload_tmp_dir
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
/** *十進位轉二進位、八進位、十六進位 不足位元前面補零* * * @param array $datalist 傳入資料array(100,123,130) * @param int $bin 轉換的進位可以是:2,8,16 * @return array 返回資料 array() 返回沒有資料轉換的格式 * @Author chengmo QQ:8292669 * @copyright
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
//此檔案用於快速測試UTF8編碼的檔案是不是加了BOM,並可自動移除//By Bob Shen$basedir="."; //修改此行為需要檢測的目錄,點表示目前的目錄$auto=1; //是否自動移除發現的BOM資訊。1為是,0為否。//以下不用改動if ($dh = opendir($basedir)) {while (($file = readdir($dh)) !== false) {if ($file!='.' && $file!='..' && !is_dir($basedir."
Time of Update: 2016-07-25
有關phpize的一點知識,中英混合,呵呵,有需要的朋友不妨一看。Compiling shared PECL extensions with phpize有關phpize的一點知識,中英混合,呵呵,有需要的朋友不妨一看。Compiling shared PECL extensions with phpizeSometimes, using the pecl installer is not an option. This could be because you're behind a
Time of Update: 2016-07-25
//要過濾的非法字元$ArrFiltrate=array(”‘”,”;”,”union”);//出錯後要跳轉的url,不填則預設前一頁$StrGoUrl=””;//是否存在數組中的值function FunStringExist($StrFiltrate,$ArrFiltrate){foreach ($ArrFiltrate as $key=>$value){if (eregi($value,$StrFiltrate)){return true;}}return
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
//檢查使用者是否登入function checklogin(){if(emptyempty($_SESSION['user_info'])){ //檢查一下session是不是為空白if(emptyempty($_COOKIE['username']) || emptyempty($_COOKIE['password'])){ //如果session為空白,並且使用者沒有選擇記錄登入狀header(”location:login.php?req_url=”.$_SERVER['REQUEST_
Time of Update: 2016-07-25
/** bbs.it-home.org */$array = array('1' => 'one', '2' => 'two', '3' => 'three'); $arrayobject = new ArrayObject($array);
Time of Update: 2016-07-25
/*** 隨機抽取數組元素* author: notuser* 2012-12-29*/class getValues {public function inputValue($inputArray) {$this->inputArray = $inputArray;}public function getValue($number) {$this->number = $number;for($i = 0; $i number; $i ++) {$index = rand ( 0, count
Time of Update: 2016-07-25
/*** Passport 解密函數** @param string 加密後的字串* @param string 私人密匙(用於解密和加密)** @return string 字串經過私人密匙解密後的結果*/function passport_decrypt($txt, $key) {// $txt 的結果為加密後的字串經過 base64 解碼,然後與私人密匙一起,// 經過 passport_key() 函數處理後的傳回值$txt = passport_key(
Time of Update: 2016-07-25
$xmlpatch = 'index.xml';$_id = '1';$_title = 'title1';$_content = 'content1';$_author = 'author1';$_sendtime = 'time1';$_htmlpatch = '1.html';$doc = new DOMDocument('1.0', 'utf-8');$doc -> formatOutput = true;$root = $doc -> createElement_x('root');/
Time of Update: 2016-07-25
$ip = "182.18.8.196";echo '';echo ip2long($ip);echo " @ ";echo $ipfu = ip2int($ip);echo ' @ ';$ip_n = bindec(decbin(ip2long($ip)));echo $ip_n;echo ' @ ';echo long2ip($ip_n);echo ' @ ';echo long2ip($ipfu);//數字轉化成IP//可以直接採用本函數來得出ip地址轉化成的數字。function
Time of Update: 2016-07-25
//畫一個很漂亮的葉子// 定義 PI 一分的角度的值define("PII", M_PI/180);// 建立映像資源,並定義其背景為 白色,前景色彩為 黑色$im = imagecreate(670,500);$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);$g = imagecolorallocate($im, 0x00, 0x00, 0x00);// 從下面執行個體化的代碼可以得知,初始值 $x, $y, $L, $a 別分為 300
Time of Update: 2016-07-25
class Connection { protected $link; private $server, $username, $password, $db; public function __construct($server, $username, $password, $db) { $this->server = $server; $this->username = $username;
Time of Update: 2016-07-25
require_once(dirname(__FILE__)."/../PHPMailer/class.phpmailer.php");//包含class.phpmailer.php/*** @param string $send_to_mail 目標郵件* @param stinrg $subject 主題* @param string $body 郵件內容* @param string $extra_hdrs 附加資訊* @param string $username 收件者*