Time of Update: 2016-07-25
/** * Detect upload file type * 檢測上傳檔案的excel檔案類型 * @param array $file * @return bool $flag * @site bbs.it-home.org */ private function detectUploadFileMIME($file) { // 1.through the file extension judgement 03 or 07 $flag = 0
Time of Update: 2016-07-25
/*** 去除數組中重複資料* by bbs.it-home.org**/$input = array("a" => "green","", "red","b" => "green", "","blue", "red","c" => "witer","hello","witer");//$result = array_unique($input); //去除重複元素$result = a_array_unique($input); //只留下單一元素foreach($result as
Time of Update: 2016-07-25
// 建立一個空的數組.$tmp_array = array();$new_array = array();// 1. 迴圈出所有的行. ( $val 就是某個行)foreach($my_array as $k => $val){ $hash = md5(json_encode($val)); if (in_array($hash, $tmp_array)) { echo('這個行已經有過了'); }else{ // bbs.it-home.org
Time of Update: 2016-07-25
function make_dir($path){ if(!file_exists($path)){//不存在則建立 $mk=@mkdir($path,0777); //許可權 @chmod($path,0777); } return true; }複製代碼函數read_filetext()取得圖片內容。使用fopen開啟圖片檔案,然後fread讀取圖片檔案內容。 function read_filetext($filepath){
Time of Update: 2016-07-25
/*** 去除重複的圖片檔案* by bbs.it-home.org*/exec("find . -type f", $lines);$arr = array();$del = array();$n = 0;foreach($lines as $line){ $line = trim($line); if(!$line){ continue; } $n ++; $md5 = md5_file($line); if(isset($arr[$md5])){ $del[] = $line; //
Time of Update: 2016-07-25
/*** 使用JpGraph產生柱狀圖* by bbs.it-home.org*/ require_once '../jpgraph/src/jpgraph.php'; require_once '../jpgraph/src/jpgraph_line.php'; require_once '../jpgraph/src/jpgraph_bar.php'; // y 軸資料,以數組形式賦值 $ydata = array(12,4,9,15,11,10,9,7,15,7); //
Time of Update: 2016-07-25
$filename = "document.txt";header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename=' . $filename);print "Hello!";?> 複製代碼用瀏覽器開啟之後,即可下載document.txt。但是,如果$filename是UTF-8編碼的,有些瀏覽器就無法正常處理了。例子: $filename = "中文
Time of Update: 2016-07-25
if ($conn=OCILogon("kai","fjelite","linux")){ echo "SUCCESS ! Connected to database/n";}else{echo "Failed :-( Could not connect to database/n";}$stmt = OCIParse($conn,"select tel,AREA from hkh_tel "); OCIDefineByName($stmt,"TEL",&$TEL);
Time of Update: 2016-07-25
/*** date函數格式化輸出指定範圍的時間* by bbs.it-home.org*/$stand = "2013-01-"; for ($i = 1; $i $time = strtotime($stand . $i); $date[] = date("Ymd", $time); } print_r($date); ?>複製代碼實現效果:附,date函數擷取前一天或後一天日期例子: //日期定義 $day = date("Ymd", strtotime(
Time of Update: 2016-07-25
public function getimgsinarticle($content) { $temp = array(); $imgs = array(); preg_match_all('/http[^\d]*[\d]+[\.](jpg|gif|png)/',$content,$temp); $temp = $temp[0]; if(!empty($temp[0])) { for($i=0;$i { $imgs[$i] = pathinfo($temp[$i]);
Time of Update: 2016-07-25
/*** 計算剩餘時間* by bbs.it-home.org*/public function gettime($time_s,$time_n){$time_s = strtotime($time_s);$time_n = strtotime($time_n);$strtime = '';$time = $time_n-$time_s;if($time >= 86400){return $strtime = date('Y-m-d H:i:s',$time_s);}if($time >= 36
Time of Update: 2016-07-25
/** * 縮小圖片函數 * 刪除了原始圖片保留了操作後的圖片 * @param string $fileName * @return void */private function createSmallImg($fileName){ list($width,$height,$type,$attr) = getimagesize($fileName); $imgOld=imagecreatefromjpeg($fileName);
Time of Update: 2016-07-25
/*** 字串替換函數* edit: bbs.it-home.org*/function replace($string,$keyArray,$replacement,$i){ $result=''; if($i $strSegArray=explode($keyArray[$i],$string); foreach ($strSegArray as $index=>$strSeg){ $x=$i+1;
Time of Update: 2016-07-25
本文介紹下,在php編程中,當上傳檔案過大時,$_files顯示為空白的解決辦法,有需要的朋友參考下。本節內容:解決PHP上傳檔案過大時$_FILES為空白的問題。在php開發的程式中,上傳圖片時,發現一張gif圖片上傳失敗 size為0,實際大小為4.66M。分享下PHP上傳檔案時檔案過大的解決方案。當上傳小檔案時可以,傳大檔案就不行,查看下PHP.INI裡面upload_max_filesize = 2M,問題往往出在這裡。修改其值: ; Maximum allowed size for
Time of Update: 2016-07-25
/*** 隨機顯示指定的文本* by bbs.it-home.org*/function getRand() { $a=rand(1,5); if ($a==1) { echo "今天晴天!"; }elseif ($a==2) { echo "今天大太陽"; }elseif ($a==3) { echo "今天下雨天"; }elseif ($a==4) { echo "今天多雲"; }elseif ($a==5) { echo "今天流星雨"; }}?>複製代碼
Time of Update: 2016-07-25
本文介紹下,php環境下的php-fpm的配置方法,對php-fpm的配置選項及方法作下詳細的介紹,有需要的朋友參考下。本節內容:php-fpm配置配置php-fpm:pid = run/php-fpm.pidpid設定,預設在安裝目錄中的var/run/php-fpm.pid,建議開啟error_log = log/php-fpm.log錯誤記錄檔,預設在安裝目錄中的var/log/php-fpm.loglog_level = notice錯誤層級。可用層級為:
Time of Update: 2016-07-25
/*** 刪除記錄時,一併刪除圖片檔案* by bbs.it-home.org*/$cn = mysql_connect('127.0.0.1','root','root') or die('database connect fail'); mysql_select_db('test',$cn); mysql_query("set names 'gbk'"); /* 建立資料庫教程 CREATE DATABASE `test` ; 建立資料表 test1 CREATE TABLE `test`.
Time of Update: 2016-07-25
/*** 屏蔽指定的IP地址訪問,但不屏蔽搜尋引擎的蜘蛛* by bbs.it-home.org*/function get_ip_data(){ $ip=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip()); $ip = json_decode($ip); if($ip->code){ return false; } $data = (array) $ip->data;
Time of Update: 2016-07-25
PHP 採集圖片函數一例 <p><?/*** 採集圖片函數* func: getimg* params: $url 網址 $filepath 圖片檔案的路徑* by bbs.it-home.org*/function getimg($url, $filepath) { </p><p> if ($url == '') {return false;}$ext = strrchr($url, '.');
Time of Update: 2016-07-25
$aa=array("apple","banana","pear","apple","wail","watermalon"); $bb=array_unique($aa); print_r($bb);?>複製代碼輸出結果:Array ( [0] => apple [1] => banana [2] => pear [4] => wail [5] => watermalon )