Time of Update: 2016-07-25
$users = array( array('name' => 'tom', 'age' => 20) , array('name' => 'anny', 'age' => 18) , array('name' => 'jack', 'age' => 22)); 複製代碼希望能按照age從小到大進行排序。方法1、使用array_multisort要將age提取出來儲存到一維數組裡,然後按照age升序排列。代碼: $ages = array();foreach ($users
Time of Update: 2016-07-25
function test() { static $b=0;//申明靜態變數,放在函數外部聲明的話,在函數內部是用不到的$b=$b+1;echo $b; } test();//這條語句會輸出 $b的值 為1 test();//這條語句會輸出 $b的值 為2複製代碼注意:static $b=0 這一賦值操作只會在變數第一次被初始化的時候執行。附A:類中靜態成員和靜態方法,差不多隻是調用的時候統一使用類名或者self或者parent加::xxx,他們的範圍和這個一樣,但是他的聲明是在方法外部的附B:
Time of Update: 2016-07-25
//php實現mysql資料匯入define("DbHost", "localhost"); //資料庫主機define("DbUser", "root"); //資料庫使用者define("DbPass", "password"); //資料庫口令mysql_connect(DbHost,DbUser,DbPass) or die("不能串連伺服器!");mysql_create_db("dbname") or die("不能建立資料庫,可能您已經安裝過了");mysql_select_db(
Time of Update: 2016-07-25
if($in = fopen('php://input', "rb")) while($buff = fread($in, 4096)) fwrite('e:\\1.jpg', $buff); 複製代碼要得到圖片資訊,那隻有getimagesize($filename),再打一次剛關閉的檔案。php中有一個getimagesizefromstring,但是要求>=php5.4。有直接操縱資料流的方法嗎?答案是有, php官方手冊上有 "支援的協議和封裝協議",其中的data://
Time of Update: 2016-07-25
$csvContent = "qwe,qwe,qwe,qwe,qwe,qwe,qwe /n"; header("Content-Type: application/vnd.ms-excel; charset=GB2312"); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
Time of Update: 2016-07-25
$list = array ( 'aaa,bbb,ccc,dddd', '123,456,789', '"aaa","bbb"' ); $fp = fopen('file.csv', 'w'); foreach ($list as $line) { fputcsv($fp, split(',', $line)); fclose($fp); }複製代碼不過低版本的php中沒有這樣的內建函數,可以自己實現一個自訂函數: function fputcsv4
Time of Update: 2016-07-25
//----------------- //檔案名稱 $filename = "test.swf"; //開啟檔案 $rs = fopen($filename, "r"); //讀取檔案的資料 $str = fread($rs, filesize($filename)); //設定swf標頭檔 $head = substr($str, 0, 8); $head[0] = 'F'; //擷取swf檔案內容 $body = substr($str, 8);
Time of Update: 2016-07-25
echo phpinfo();?>複製代碼儲存,然後通過瀏覽器開啟phpinfo.php,搜尋‘gd’,看是否有以下這項: 如果有說明系統已支援了GD庫,如果沒有需要重新編譯一下PHP以支援GD庫。 三,GD支援的映像格式GD庫預設不支援所有的映像格式,通過上面那張圖 的資訊,可以看出系統的GD庫支援哪些格式的圖片,JPG Support表示支援JPG格式的,沒有列出來的就不被支援。 四,GD函數的分類GD函數我覺得可以分成6大類:1,獲得資訊2,建立映像3,畫圖4,拷貝5,輸出6,銷毀>>>
Time of Update: 2016-07-25
include("config.php");// load libraryrequire 'php-excel.class.php';// create a simple 2-dimensional array//@mysql_query("set character set gb2312");$strSql="select * from booklist";$result=mysql_query($strSql);//print_r($result);$data = array(1 =>
Time of Update: 2016-07-25
分享下在用php匯出csv檔案時,社會安全號碼碼禁止以科學計數顯示的方法,有需要的朋友參考下。其實,很簡單啦。PHP 匯出 csv 檔案,開啟後會發現,社會安全號碼採用科學計數方法表示。解決的方法:在前面添加 "\t"小貼士:phpexcel 匯出的方法也同上一樣。在前面添加 " "空格即可。更多內容,請參考:php匯出csv,php產生csv。
Time of Update: 2016-07-25
/** * 儲存網頁檔案到本地(用於採集圖片) * edit: bbs.it-home.org * @param 檔案路徑 $sUrl * @param 儲存本地路徑 $sSavePath * @return boolean */ function download_file($sUrl,$sSavePath='') { $sFileName = GetUrlFileExt($sUrl); $c = file_get_contents($sUrl);
Time of Update: 2016-07-25
/** * 產生預設以逗號分隔的CSV檔案 * 解決:內容中包含逗號(,)、雙引號("") * @author zf Edit: bbs.it-home.org * @version 2012-11-14 */header("Content-Type: application/vnd.ms-excel; charset=GB2312");header("Content-Disposition: attachment;filename=CSV資料.csv "); $rs = array(
Time of Update: 2016-07-25
$im = imagecreate(200,150);echo $im;?>//輸出Resource id #1複製代碼二,magecreatetruecolor - 建立一個真彩色的畫布1,格式:imagecreatetruecolor ( int x_size, int y_size )2,解析:同imagecreate一樣,建立一個空白的畫布,區別在於這個函數建立的畫布支援的色彩數更多,所以效果更好,傳入畫布寬度和高度的像素值,返回的是系統分配給這塊畫布的id號,例如: $im =
Time of Update: 2016-07-25
header("Content-type:application/vnd.ms-excel");header("content-Disposition:filename=downloaded.pdf ");echo"1\t 2\t 3\n"; //其中 \t 是空白 ,\n是斷行符號 (編碼規範 不能直接輸出)echo"1\t 2\t 3\n";echo"1\t 2\t 3\n";?> 複製代碼此時開啟這個php檔案,就會提示下載。也可以以table表格的方式輸出;
Time of Update: 2016-07-25
tar xzvf zlib-1.2.3.tar.gzcd zlib-1.2.3./configuremakemake install複製代碼2、安裝freetype tar xzvf freetype-2.2.1.tar.gzcd freetype-2.2.1./configuremakemake install複製代碼3、安裝libpng tar xzvf libpng-1.2.12.tar.gzcd libpng-1.2.12cp scripts/makefile.std
Time of Update: 2016-07-25
header("Content-type:image/jpeg") 複製代碼GD庫中有對應的image類型 imagejpeg(),imagegif(),imagepang()5,imageline畫線函數 iamgeline(resource image,int x1,int y1,int x2,int y2,int color); image ---圖片 x1 ---啟始座標 y1 x2 ---終點座標 y26,imagesetpixel畫點函數
Time of Update: 2016-07-25
//class utf8_chinese{ private $utf8_gb2312; private $utf8_big5; public function __construct(){ $this->utf8_gb2312 =
Time of Update: 2016-07-25
$fname = $_FILES['MyFile']['name']; $do = copy($_FILES['MyFile']['tmp_name'],$fname); if ($do){ echo"匯入資料成功"; }else{ echo ""; } ?> error_reporting(0);//匯入CSV格式的檔案 $connect=mysql_connect("localhost","a0530093319","123456") or die("could not connect
Time of Update: 2016-07-25
分享下php gd庫中的常用函數,配有中文注釋,並做了分類處理,包括 映像資訊、建立/載入映像、輸出映像等php gd庫函數,有需要的朋友參考下。本節內容:php gd庫的函數大全。1,映像資訊: gd_info 取得當前安裝的 GD 庫的資訊imagetypes 返回當前 PHP 版本所支援的映像類型image_type_to_extension 取得映像類型的檔案尾碼image_type_to_mime_type 取得 映像類型的 MIME 類型getimagesize
Time of Update: 2016-07-25
/*** php 遍曆目錄與檔案* by bbs.it-home.org*/function scan_all($dir){ $temp = scandir($dir); if(is_array($temp) && count($temp)>2){ array_shift($temp); array_shift($temp); foreach($temp as $v){