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
function writeMyName() { // bbs.it-home.org echo "jeremyLin"; }writeMyName(); ?> 複製代碼2,函數 - 添加參數第一個函數是一個非常簡單的函數。它只能輸出一個靜態字串。通過可以添加參數,向函數添加更多的功能。參數類似一個變數。例子: function writeMyName($fname) { // bbs.it-home.org echo $fname . "jeremy."; }
Time of Update: 2016-07-25
// 冒泡排序function BubbleSort($arr) { // 獲得數組總長度 $num = count($arr); // 正向遍曆數組 for ($i = 1; $i // 反向遍曆 for ($j = $num - 1; $j >= $i ; $j--) { // 相鄰兩個數比較 if ($arr[$j] // 暫存較小的數
Time of Update: 2016-07-25
/* 二維數組按指定的索引值排序 * $array 數組* $key排序索引值* $type排序方式* @edit: bbs.it-home.org*/function array_sort($arr, $keys, $type = 'desc') { $keysvalue = $new_array = array(); foreach ($arr as $k => $v) { $keysvalue[$k] = $v[$keys]; } if ($type
Time of Update: 2016-07-25
echo time(); // return "1264668961" ?> 複製代碼2,date()需要將UNIX時間戳記轉換為可閱讀的目前時間,就要用到date()函數。date函數的原型如下: echo date("Y/m/d"); echo ""; echo date("Y.m.d"); echo ""; echo date("Y-m-d"); ?> 複製代碼輸出:2013/11/212013.11.212013-11-213,mktime()mktime()
Time of Update: 2016-07-25
學完HTML以及PHP基礎後,寫這個項目也有一段時間了,在寫的過程中可以說是更加系統化了所學習過的一些東西,也更加深刻了一些所謂經驗需要積累的道理。在之前學習基礎知識的時候尚且感覺這些比較簡單的知識還是能夠駕馭的,在寫項目的時候才更能深刻的感覺到對知識的理解程度以及熟練程度的欠缺,甚至可以說有些知識細節還是需要在以後漫長的工作中慢慢積累,才能漸豐羽翼。每次項目的總結便是一個積累的時段,藉此,歸納一下自己在這個手敲代碼的過程中的一些細微的成長,思想的雛形。以下將就我本次寫出的作品而言,淺述一些思考
Time of Update: 2016-07-25
$str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); ?> 複製代碼2、字串的串連 例子: //定義字串 $str1 = "Hello World!"; $str2 = "PHP !"; //串連上面兩個字串 中間用空格分隔 $str3 = $str1 . " " . $str2; //輸出串連後的字串 echo $str3; 複製代碼3、字串的截取
Time of Update: 2016-07-25
function d_rmdir($dirname) { //刪除非空目錄 if(!is_dir($dirname)) { return false; } // bbs.it-home.org$handle = @opendir($dirname); while(($file = @readdir($handle)) !== false){ if($file != '.' && $file != '..'){ $dir = $dirname . '/' . $file;
Time of Update: 2016-07-25
-- -- 資料庫: `db_copy_old` -- -- -- 表的結構 `article` -- CREATE TABLE IF NOT EXISTS `article` ( `id` int(20) NOT NULL auto_increment, `title` text character set utf8 NOT NULL, `content` text character set utf8 NOT NULL, PRIMARY KEY
Time of Update: 2016-07-25
if (!empty($_FILES["img"]["name"])) { //提取檔案域內容名稱,並判斷 $path=”uppic/”; //上傳路徑 if(!file_exists($path)) { //檢查是否有該檔案夾,如果沒有就建立,並給予最高許可權 mkdir(“$path”, 0700); }//END IF //允許上傳的檔案格式 $tp = array(“image/gif”,”image/pjpeg”,”image/jpeg”); //檢查上傳檔案是否在允許上傳的類型
Time of Update: 2016-07-25
/*** 中文字串截取函數* by bbs.it-home.org*/function cut_str($string,$sublen,$filter=true,$start=0,$code='UTF-8'){ if($filter) $string=Html2Text($string); if($code=='UTF-8'){ $pa="/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80
Time of Update: 2016-07-25
/*** func: delete_file* params: $file 檔案名稱* 多重條件判斷 刪除檔案* by bbs.it-home.org*/function delete_file($file) { if (file_exists($file)) { $delete = chmod ($file, 0777); $delete = unlink($file); if(file_exists($file))
Time of Update: 2016-07-25
/*** php二維數組按指定索引值key排序* by bbs.it-home.org*/function array_sort($array, $key){ if(is_array($array)){ $key_array = null; $new_array = null; for( $i = 0; $i $key_array[$array[$i][$key]] = $i; } ksort($key_array); $j = 0; foreach($key_array as $k =>
Time of Update: 2016-07-25
/*** php檔案下載代碼,中文無亂碼* by bbs.it-home.org*/ $file = "/tmp/中文名.tar.gz"; $filename = basename($file); header("Content-type: application/octet-stream"); //處理中文檔案名稱 $ua = $_SERVER["HTTP_USER_AGENT"]; $encoded_filename =
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
/*** 隨機顯示指定的文本* 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
/*** 刪除記錄時,一併刪除圖片檔案* 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, '.');