Time of Update: 2016-07-25
處理代碼: header('Content-Type:text/html;charset=UTF-8'); //準備接收 /* echo '檔案名稱:'.$_FILES['userfile']['name']; echo '檔案大小:'.$_FILES['userfile']['size']; echo '錯誤:'.$_FILES['userfile']['error']; */
Time of Update: 2016-07-25
test();/** * 測試 */function test() { echo CnToInt('一'); // 1 echo CnToInt('十'); // 10 echo CnToInt('十一'); // 11 echo CnToInt('一百一十'); // 110 echo CnToInt('一千零一'); // 1001 echo CnToInt('一萬零一百零一'); // 10101 echo
Time of Update: 2016-07-25
require './class.phpmailer.php';$mail=new
Time of Update: 2016-07-25
$handle = @ fopen ( "demo.txt" , "r" ); if ( $handle ) { while (( $buffer = fgets ( $handle , 4096 )) !== false ) { echo $buffer ; } if (! feof ( $handle )) { echo "Error: unexpected
Time of Update: 2016-07-25
在web開發中,可以通過檔案快取,大大緩解資料庫的壓力。 如下代碼是php中使用檔案快取的例子。 CacheLayer.php class CacheLayer{ protected $root = ""; protected $cache = ""; protected $key = ""; protected $life = 0; public function __construct($key, $root = "/cachelayer"){
Time of Update: 2016-07-25
Profiling是一項用來觀察程式效能的技術,非常適用於發現程式的瓶頸或者緊張的資源。Profiling能夠深入程式的內部,展現request處理過程中每一部分代碼的效能;同時,也可以確定有問題的請求(request);對於有問題的請求,我們還可以確定效能問題發生在請求內部的位置。對於PHP,我們有多種Profiling工具,本文主要集中在——XHGui,一款非常優秀的工具。XHGui構建在XHProf之上(XHProf由Facebook發布),但是對於剖析結果增加了更好的儲存,同時增加了更加
Time of Update: 2016-07-25
// 指定檔案路徑和縮放比例 $filename = 'test.jpg'; $percent = 0.5; // 指定標頭檔Content typezhi值 header('Content-type: image/jpeg'); // 擷取圖片的寬高 list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // 建立一個圖片。
Time of Update: 2016-07-25
php使用imagecopy()拼接圖片 header("Content-type: image/jpeg"); $src_image[0] = imagecreatefromgif("./1.jpg");$src_image[1] = imagecreatefromgif("./2.jpg"); $dest = imagecreatetruecolor(100, 50); //php圖片拼接imagecopy($dest, $src_image[0], 0, 0, 0, 0, 50, 50);
Time of Update: 2016-07-25
error_reporting(7);define('ROOT', getcwd());define('BASEDIR', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));if ($_POST['text']) { $ret = array(); $text = $_POST['text']; try { $ret['imgurl'] = text2img($text, (array)
Time of Update: 2016-07-25
class HRDB{ protected $pdo; protected $res; protected $config; /*建構函式*/ function __construct($config){ $this->Config = $config; $this->connect(); } /*資料庫連接*/ public function connect(){
Time of Update: 2016-07-25
下面簡單的寫了一個圖片處理類,功能包括:浮水印,縮圖等。 不過,對於產生縮圖有兩種方式:一種是直接按比例來壓縮圖片,另外一種是先裁剪再壓縮的方式。在自己看來等例壓縮與裁剪壓縮區別就在於: 等例壓縮:能保證圖片的寬長比例合理,且圖片有完整性。但實際大小不保證符合要求。 裁剪壓縮: 能保證圖片的寬長比例合理,實際大小也能保證。但圖片完整性不能保證。 image.php /** * * 影像處理類 * @author FC_LAMP * @internal功能包含:浮水印,縮圖 */class
Time of Update: 2016-07-25
//把全形數字轉為半形數字 function GetAlabNum($fnum){ $nums = array("0","1","2","3","4","5","6","7","8","9");//OSPHP.com.CN$fnums = "0123456789"; for($i=0;$i$fnum = ereg_replace("[^0-9.]|^0{1,}","",$fnum); if($fnum=="") $fnum=0; return
Time of Update: 2016-07-25
class Cookie{ /** * 解密已經加密了的cookie * * @param string $encryptedText * @return string */ private static function _decrypt($encryptedText) { $key = Config::get('secret_key'); $cryptText =
Time of Update: 2016-07-25
class database { private $hostname; private $user; private $pass; private $dbname; private $linkflag; private $charset; function __construct() { $this->hostname="localhost";
Time of Update: 2016-07-25
這是用開源項目PHPMailer實現郵件發送 ,先下載檔案,我這裡下載得是5.1得版本,然後把三個class.***.php檔案放到專案檔下,我首先用得是 gmail,但是失敗了,問題是認證失敗,後來用了QQ郵箱,發送成功。 require("class.phpmailer.php"); //下載的檔案必須放在該檔案所在目錄$mail = new PHPMailer(); //建立郵件發送類$address ="youbinliu@126.com";$mail->IsSMTP(); //
Time of Update: 2016-07-25
php按照指定長度截取字串的代碼,如果字串超出了指定的長度,會用...替換,不過這段代碼不支援中英文的區分 //if a string is longer than the defined length, //it will add 3 periods to the end of the string.//you can change it to what ever you want for example://return substr($str,0,$len).'[Read More]';
Time of Update: 2016-07-25
這段php代碼詳細示範了如何開啟檔案、讀取檔案和關閉檔案,php中可以通過fopen開啟檔案,通過filesize函數擷取檔案大小,fread讀取檔案內容,fclose關閉檔案 Reading a file using PHP $filename = "/home/user/guest/tmp.txt";$file = fopen( $filename, "r" );if( $file == false ){ echo ( "Error in opening file" );
Time of Update: 2016-07-25
只要以數組形式來命名表單中的檔案上傳標記,即可實現多個檔案同時上傳。 下面我們來看一個例子: --------------------------------------------------------------------- function upload($file_error, $file_tmp_name, $file_name){ $info = ""; if($file_name == "") return
Time of Update: 2016-07-25
php 四捨五入的三種方法,分別通過number_format函數、round函數和sprintf格式化輸出的方法實現四捨五入 1.number_format 方法實現四捨五入 $number = 1234.5678; $nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234,57 $english_format_number = number_format($number, 2, '.', '');
Time of Update: 2016-07-25
class sqlsafe { private $getfilter = "'|(and|or)\\b.+?(>| private $postfilter = "\\b(and|or)\\b.{1,6}?(=|>| private $cookiefilter = "\\b(and|or)\\b.{1,6}?(=|>| /** * 建構函式 */ public function __construct() { foreach($_GET