Time of Update: 2016-07-25
使用下面的函數可以擷取任何網域名稱使用者的完整細節 function whois_query($domain) { // fix the domain name: $domain = strtolower(trim($domain)); $domain = preg_replace('/^http:\/\//i', '', $domain); $domain = preg_replace('/^www\./i', '', $domain); $domain =
Time of Update: 2016-07-25
php內建的rmdir,只能刪除空目錄,這個rrmdir就可以遞迴刪除目錄及目錄下的所有檔案 function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != “.” && $object != “..”) { if (filetype($dir.”/”.$object) ==
Time of Update: 2016-07-25
/** * 數字轉換為中文 * @param string|integer|float $num 目標數字 * @param integer $mode 模式[true:金額(預設),false:普通數字表示] * @param boolean $sim 使用小寫(預設) * @return string */ function number2chinese($num,$mode = true,$sim = true){
Time of Update: 2016-07-25
這個程式碼片段可以方便你禁止某些特定的 IP 位址訪問你的網站 if ( !file_exists('blocked_ips.txt') ) { $deny_ips = array( '127.0.0.1', '192.168.1.1', '83.76.27.9', '192.168.1.163' );} else { $deny_ips = file('blocked_ips.txt');}// read user ip adress:$ip =
Time of Update: 2016-07-25
這段代碼可以檢測使用者是否使用行動裝置瀏覽網頁,檢驗非常完整 $mobile_browser = '0'; if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))){ $mobile_browser++; }
Time of Update: 2016-07-25
// $low and $high have to be integers function BinarySearch( $array, $key, $low, $high ){ if( $low > $high ) // termination case { return -1; } $middle = intval( ( $low+$high )/2 ); // gets the middle of the array if ( $array[
Time of Update: 2016-07-25
這段代碼可以協助你判斷任意圖片的主色調,使用了簡單的統計演算法實現 $i = imagecreatefromjpeg("image.jpg"); for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF;
Time of Update: 2016-07-25
/** * 郵件發送類 * 支援發送純文字郵件和HTML格式的郵件 * @example * $config = array( * "from" => "*****", * "to" => "***", * "subject" => "test", * "body" => "test", * "username" => "***", *
Time of Update: 2016-07-25
//filetype()擷取檔案的類型//擷取windows下的檔案類型echo filetype("D:\\lamp\\php5\\php.ini")."";//輸出file 表示是一個普通檔案echo filetype("D:\\lamp\\php5")."";//輸出dir 表示是一個目錄//is_file()判斷給定的檔案名稱是否是一個普通檔案//is_dir()判斷給定的檔案名稱是否是一個目錄//file_exists()檢查檔案或目錄是否存在//filesize()取得檔案的大小//
Time of Update: 2016-07-25
//檔案本身的操作 //copy()複製檔案 //unlink()刪除檔案 //ftruncate()將檔案截斷到指定的長度 //rename()重新命名檔案或目錄 if(copy("data.txt","data_bak.txt")){//複製檔案執行個體 echo "檔案複製成功"; }else{ echo "檔案複製失敗"; } if(file_exists("data_bak.txt")
Time of Update: 2016-07-25
$image=imagecreatetruecolor(100, 30);$white=imagecolorallocate($image, 255, 255, 2);$red=imagecolorallocate($image, 255, 0, 0);imagefill($image, 0, 0, $white);//munber create$num="";for($i=0;$i $num.=rand(1,9);}imagestring($image, 6, rand(10,
Time of Update: 2016-07-25
本文執行個體講述了phpRegex取得內容所有連結的方法。分享給大家供大家參考。具體如下: 這裡提供二款關於php正則連結的方法,他們可以取得內容所有連結並且儲存到一個數組,當然也可以把連結全部替換. 方法一,代碼如下: function get_all_url($code){ preg_match_all('/"' ]+)["|']?s*[^>]*>([^>]+)/i',$code,$arr); return array('name'=>$arr[2],
Time of Update: 2016-07-25
require("class.phpmailer.php");$mail = new PHPMailer();$mail = new PHPMailer();$mail->IsSMTP();$mail->Host = "smtp1.example.com;smtp2.example.com";$mail->SMTPAuth = true;$mail->Username = 'smtpusername';$mail->Password = 'smtppassword'; $mail->From="
Time of Update: 2016-07-25
/* function:二維數組按指定的索引值排序 $array=array( 0=>array('id'=>8,'username'=>'phpernote'), 1=>array('id'=>9,'username'=>'com'), 2=>array('id'=>5,'username'=>'www') ); 現在需要將這個二維數組按id升序排列,則: array_sort($array,'id','asc'); */ public function array_
Time of Update: 2016-07-25
//PHP 添加浮水印 & 比例縮圖 & 固定高度 & 固定寬度 類。 class Image_process{ public $source; //原圖 public $source_width; //原圖寬度 public $source_height; //原圖高度 public $source_type_id; public $orign_name; public $orign_dirname; /
Time of Update: 2016-07-25
大概原理 遍曆項目中的所有非排除檔案,然後擷取 檔案修改時間晚於檔案上一次修改時間 的檔案 然後將這些檔案,通過ftp上傳到對應的目錄 具體代碼如下: 因為只是工具,代碼很亂,見諒 error_reporting(7);if ($_SERVER['SERVER_ADDR'])exit;//禁止在web伺服器下運行$_GET['exclude'] =
Time of Update: 2016-07-25
$date1 = date( 'Y-m-d' );$date2 = "2015-12-04";$diff = abs(strtotime($date2) - strtotime($date1));$years = floor($diff / (365*60*60*24));$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));$days = floor(($diff - $years * 365*60*60*24 - $
Time of Update: 2016-07-25
function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); for($i = 1;$i $file = trim(preg_replace("~inflating: ~","",$arr[$i])); copy($location.'/'.$file,
Time of Update: 2016-07-25
之前我們提供了如何使用 Mandrill 發送郵件的 PHP 程式碼片段,但是如果你不想使用第三方服務,那麼可以使用下面的 PHP 程式碼片段。 function send_mail($to,$subject,$body){$headers = "From: KOONK\r\n";$headers .= "Reply-To: blog@koonk.com\r\n";$headers .= "Return-Path: blog@koonk.com\r\n";$headers .=
Time of Update: 2016-07-25
function dominant_color($image){$i = imagecreatefromjpeg($image);for ($x=0;$x for ($y=0;$y $rgb = imagecolorat($i,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; $rTotal += $r;