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
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
$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
/** * 傳送檔案 * * @param string $fileName 檔案名稱或路徑 * @param string $fancyName 自訂的檔案名稱,為空白則使用filename * @param boolean $forceDownload 是否強制下載 * @param integer $speedLimit 速度限制,單位為位元組,0為不限制,不支援windows伺服器 * @param string $$contentType
Time of Update: 2016-07-25
/*** 截取中英文混合的字串* by bbs.it-home.org*/function mb_str_split($string){ # Split at all position not after the start: ^ # and not before the end: $ //$string = iconv('gb2312', 'utf-8//ignore', $string); return
Time of Update: 2016-07-25
//遞迴獲得角色ID字串function explodeRole($roleObj, &$resultStr){ if(0 childRoleObjArr)){ foreach($roleObj->childRoleObjArr as $childRoleObj){ if('' == $resultStr){ $resultStr .= "{$childRoleObj->id}"; }else{
Time of Update: 2016-07-25
function http_open($url, $data, $cookie = null, $method = "GET", $timeout = 60) { $options = array(); $options['http']['method'] = $method; $options['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $options['http']['timeout'] = $timeout;
Time of Update: 2016-07-25
/*** 讀取 sql 檔案並寫入資料庫 * @version 1.01 demo.php * @author xingshaocheng* @edit: bbs.it-home.org*/class DBManager{ var $dbHost = ''; var $dbUser = ''; var $dbPassword = ''; var $dbSchema = ''; function
Time of Update: 2016-07-25
function DJBHash($str) // 0.22{$hash = 0;$n = strlen($str);for ($i = 0; $i {$hash += ($hash }return $hash % 701819;} function ELFHash($str) // 0.35{$hash = $x = 0;$n = strlen($str); for ($i = 0; $i {$hash = ($hash if(($x = $hash & 0xf0000000) != 0){$
Time of Update: 2016-07-25
AuthType Basic AuthName "restricted area" AuthUserFile /full/path/to/passwordprotected/.htpasswd require valid-user 複製代碼第一行的AuthType指的是採用的認證方式,在這裡我們選擇的是一般的Basic,要注意的是,Basic認證方式傳輸密碼過程是不加密的,更安全的
Time of Update: 2016-07-25
$number = array(1,3,5,7,9); $color =array("red","blue","green"); $student = array("name",17) ?>複製代碼例2: $language = array(1=>"PHP",3=>"JAVA",4=>"C"); $student = array("name"=>"張三","age"=>17) ?>複製代碼當然,數組裡沒有值也是允許的,即空數組: $result = array();
Time of Update: 2016-07-25
imagecolorallocatealpha //分配顏色 + alphaimagesavealpha //設定在儲存 png 映像時儲存完整的 Alpha 色板資訊複製代碼完整代碼: //擷取源圖gd映像標識符$srcImg = imagecreatefrompng('./src.png');$srcWidth = imagesx($srcImg);$srcHeight = imagesy($srcImg);//建立新圖 bbs.it-home.org$newWidth =
Time of Update: 2016-07-25
/** * GD image text outer * * @copyright UGiA.CN * [url=home.php?mod=space&uid=17823]@LINK[/url] www.ugia.cn/?p=88 * @edit bbs.it-home.org */function imagetextouter(&$im, $size, $x, $y, $color, $fontfile, $text, $outer){ if
Time of Update: 2016-07-25
forceDownload("pdfdemo.pdf"); function forceDownload($filename) {if (false == file_exists($filename)) { return false; }// http headers header('Content-Type: application-x/force-download'); header('Content-Disposition: attachment; filename="' .
Time of Update: 2016-07-25
[root@jbxue ~]# rpm -qa|grep phpphp-pear-1.4.6-2php-5.1.2-5php-gd-5.1.2-5php-ldap-5.1.2-5複製代碼2、卸載以上列出的RPM包: [root@jbxue ~]# rpm -e php-pear-1.4.6-2 php-5.1.2-5 php-gd-5.1.2-5 php-ldap-5.1.2-5複製代碼3、進入/var/php目錄: [root@jbxue ~]# cd
Time of Update: 2016-07-25
mysql_query("select max(id) from t1",$link);複製代碼使用此方法得到的是 id最大的值,確為最後一個值,但當多連結線程時,這個最大的id並不一定是我們插入資料的自增id值,因此不適用於多線程。二,使用函數:msyql_insert_id();當系統執行完INSERT後,再執行SELECT時,可能已經被分發到了不同的後端伺服器,如果使用php編程,此時應該通過
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){
Time of Update: 2016-07-25
//header("Cache-Control: public"); header('content-type:application/vnd.ms-excel'); header("Content-Disposition:attachment; filename=report.xls");複製代碼如果不加第一句,會彈出 : Internet Explorer 無法下載 **.php (來自**網站)。Internet Explorer無法開啟該 internet
Time of Update: 2016-07-25
#yum -y install mysql mysql-server mysql-devel複製代碼配置mysql開機啟動服務 #chkconfig --add mysqld (在服務資訊清單中添加mysql服務) #chkconfig mysqld on (設定mysql服務隨開機啟動) #service mysqld start (啟動mysql服務)複製代碼二、安裝PHP #yum -y install php #service httpd restart (重啟apache)
Time of Update: 2016-07-25
/*** php socket smtp發送郵件* edit: bbs.it-home.org*///define("SOL", "\n");define("EOL", "\r\n");define("SMTP_HOST", "smtp.163.com");//SMTP伺服器define("SMTP_PORT", "25");//SMTP伺服器連接埠define("SMTP_USER", "");//SMTP伺服器的使用者帳號define("SMTP_PASS",