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
//basename()返迴路徑中的檔案名稱部分$path="D:/lamp/apache2/htdocs/file.php";echo basename($path)."";//顯示帶有副檔名的檔案名稱echo basename($path,'php')."";//顯示不帶副檔名的檔案名稱//dirname()去掉檔案名稱,返回目錄名echo dirname($path)."";//返回目錄名//pathinfo()返回一個關於路徑屬性的數組print_r(pathinfo($path))."
Time of Update: 2016-07-25
給定一段文本,此程式碼分析文本的詞頻分布,產生tag雲 /** * Tag cloud demo based on word frequency * @author: unknown * @since: 2007-02-27 */ // Store frequency of words in an array$freqData = array(); // Random words$lorem = "Lorem ipsum dolor sit amet, consectetuer
Time of Update: 2016-07-25
//第一段代碼產生隨機圖片------code2.php //開啟session以用於儲存產生的內容session_start();$table=array( "pic0"=>"dog", "pic1"=>"cat", "pic2"=>"fish", "pic3"=>"bird");$index=rand(0,3);$value=$table['pic'.$index];
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
PHP陽曆到農曆轉換的一個類代碼 //PHP陽曆到農曆轉換的一個類class Calendar{#農曆每月的天數 var $everyCMonth=array( 0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1), 1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2), 2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3),
Time of Update: 2016-07-25
這個有用的函數能將秒數表示的事件轉換為年、月、日、小時等時間格式 function Sec2Time($time){if(is_numeric($time)){$value = array("years" => 0, "days" => 0, "hours" => 0,"minutes" => 0, "seconds" => 0,);if($time >= 31556926){$value["years"] = floor($time/31556926);$time = ($time%3155
Time of Update: 2016-07-25
/** * */ function getfirstchar($s0){ if($s0[0]=='I' || $s[0]=='i'){ return "I"; }elseif($s0[0]=='U' || $s[0]=='u'){ return 'U'; }elseif($s0[0]=='V' ||
Time of Update: 2016-07-25
這是一個非常有用的距離計算函數,利用緯度和經度計算從 A 地點到 B 地點的距離。該函數可以返回英裡,公裡,海裡三種單位類型的距離。 function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2;$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2
Time of Update: 2016-07-25
//格式化時間,幾分鐘前,幾小時前 function format_date($time){ $t = time()-$time; $f = array( '31536000'=>'年', '2592000'=>'個月', '604800'=>'星期', '86400'=>'天', '3600'=>'小時',
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
function getLocationInfoByIp(){ $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = @$_SERVER['REMOTE_ADDR']; $result = array('country'=>'', 'city'=>''); if(filter_var($client, FILTER_VALIDATE_IP)){ $ip =
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
class HttpTool{ /** * //擷取網域名稱或主機地址 * #測試網址: http://localhost:8081/test/testurl.php?id=5 * 返回 localhost:8081 */ public function getHost() { return $_SERVER['HTTP_HOST']; } /** * 當前頁面的url(包括參數)
Time of Update: 2016-07-25
/* * 遠程圖片擷取到本地 */ function GrabImage($url){ if($url != ""){ //如果圖片地址為空白 $ext = strrchr($url,'.'); //判斷圖片的格式 if($ext != '.jpg' && $ext != '.gif' && $ext != '$png'){ return
Time of Update: 2016-07-25
function shorturl($url){ $length = strlen($url); if($length > 45){ $length = $length - 30; $first = substr($url, 0, -$length); $last = substr($url, -15); $new = $first."[ ... ]".$last; return $new; }else{ return $url; }}?> // USAGE $longurl= "http:/
Time of Update: 2016-07-25
$patterns = "/\d+/"; //第一種 //$patterns = "/\d/"; //第二種 $strs="left:0px;top:202px;width:90px;height:30px"; preg_match_all($patterns,$strs,$arr); print_r($arr); /***************運行結果*********************/ //第一種Array( [0] => Array
Time of Update: 2016-07-25
本文執行個體講述了php實現的支援斷點續傳的檔案下載類及其用法,是非常實用的技巧。分享給大家供大家參考。具體方法如下: 通常來說,php支援斷點續傳,主要依靠HTTP協議中 header HTTP_RANGE實現。 HTTP斷點續傳原理: Http頭 Range、Content-Range() HTTP頭中一般斷點下載時才用到Range和Content-Range實體頭, Range使用者要求標頭中,指定第一個位元組的位置和最後一個位元組的位置,如(Range:200-300)
Time of Update: 2016-07-25
大概原理 遍曆項目中的所有非排除檔案,然後擷取 檔案修改時間晚於檔案上一次修改時間 的檔案 然後將這些檔案,通過ftp上傳到對應的目錄 具體代碼如下: 因為只是工具,代碼很亂,見諒 error_reporting(7);if ($_SERVER['SERVER_ADDR'])exit;//禁止在web伺服器下運行$_GET['exclude'] =