/** * 常用對稱式加密演算法類 * 支援通行金鑰:64/128/256 bit(位元組長度8/16/32) * 支援演算法:DES/AES(根據密鑰長度自動匹配使用:DES:64bit AES:128/256bit) * 支援模式:CBC/ECB/OFB/CFB * 密文編碼:base64字串/十六進位字串/二進位字串流 * 填充方式: PKCS5Padding(DES) * * @author: linvo * @version: 1.0.0 * @date: 2013/1/10 */
#改變數組鍵的大小寫 $arr1=array("a"=>"Lamp","db"=>"database","LANGUAGE"=>"PHP"); print_r(array_change_key_case($arr1,CASE_UPPER)); echo ""; print_r(array_change_key_case($arr1,CASE_LOWER)); echo ""; #將一個數組分割成多個 第三個參數設定是否保留鍵 $arr2=array('a','b','c','d','e','f'
通過openssl實現的簽名、驗簽、非對稱加解密,需要配合x.509認證(如crt和pem)檔案使用。 /** * RSA演算法類 * 簽名及密文編碼:base64字串/十六進位字串/二進位字串流 * 填充方式: PKCS1Padding(加解密)/NOPadding(解密) * * Notice:Only accepts a single block. Block size is equal to the RSA key size! * 如密鑰長度為1024 bit,則加密時資料需小於1
PHP ZipArchive 是PHP內建的擴充類,可以輕鬆實現ZIP檔案的壓縮和解壓,使用前首先要確保PHP ZIP 擴充已經開啟。 /* 說明: 將多個檔案壓縮成一個zip檔案的函數 * @param $files 數群組類型 * @param destination 目標檔案的路徑 * @param $overwrite 是否為覆蓋與目標檔案相同的檔案 */function create_zip($files = array(),$destination
/* set here a limit of downloading rate (e.g. 10.20 Kb/s) */ $download_rate = 10.20; $download_file = 'download-file.zip'; $target_file = 'target-file.zip'; if(file_exists($download_file)){ /* headers */ header(
//取出url地址中副檔名$url = "http://sdk.tools.sinaapp.com/index.php?appname=beipiao&version=1";function getFileName($url){$a = explode('?', $url);$b = strrpos($a[0], '.'); //strrpos(被搜尋字串,要尋找字串,[尋找開始的位置]) 尋找字串最後一次出現的位置: 找到則返回最後一次出現的位置;未找到則返回false$c =
define('DS', DIRECTORY_SEPARATOR); class getDirFile{ //返回數組 private $DirArray = array(); private $FileArray = array(); private $DirFileArray = array(); private $Handle,$Dir,$File; //擷取目錄列表 public function
function http_post_data($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_HTTPHEADER,
#####################//CONFIGURATIONS #####################// Define the name of the backup directorydefine('BACKUP_DIR', './myBackups' ) ;// Define Database Credentialsdefine('HOST', 'localhost' ) ;define('USER', 'testd!b' ) ;define('PASSWORD', 'k^
function resizeimage($srcfile,$mySize){ $size=getimagesize($srcfile); switch($size[2]){ case 1: $img=imagecreatefromgif($srcfile); break; case 2:
登入註冊訂閱RSS網站地圖指令碼分享網 // cookieClass // Copyright (C) 2005 JRSofty Programming. // http://jrsofty1.stinkbugonline.com // Licensed under GNU/GPL class cookieClass{ var $cName = ''; var $cTime = ''; var
在php計算字串相似性similar_text與相似性levenshtein函數的詳細介紹 $first = "abcdefg"; $second = "aeg"; echo similar_text($first, $second);結果輸出3.如果想以百分比顯示,則可使用它的第三個參數,如下: $first = "abcdefg"; $second = "aeg"; similar_text($first, $second, $percent); echo $percent;
function pdf2png($PDF,$Path){ if(!extension_loaded('imagick')){ return false; } if(!file_exists($PDF)){ return false; } $IM = new imagick(); $IM->setResolution(120,120); $IM->setCompressionQuality(100);
/* * 中文圓形印章類 * @author lkk/lianq.net * @create on 10:03 2012-5-29 * @example: * $seal = new circleSeal('你我他坐站走東西南北中',75,6,24,0,0,16,40); * $seal->doImg(); */class circleSeal { private $sealString; //印章字元 private $strMaxLeng; //最大字元長度
在很多場合為了顯示出資訊的及時性,一般會將時間顯示成“剛剛”,“5分鐘前”,“3小時前”等,而不是直接將時間列印出來。比如微博,SNS類應用就最 長用到這個功能。而一般儲存在資料庫中的時間格式為 Unix時間戳記,所以這裡記錄一個將 Unix時間戳記 轉化為時間軸顯示的PHP函數。 date_default_timezone_set('PRC');$date = "1351836000";echo tranTime($date); function transfer_time($time){
function DateDiff($date1, $date2, $unit = "") { //時間比較函數,返回兩個日期相差幾秒、幾分鐘、幾小時或幾天 switch ($unit) { case 's': $dividend = 1; break; case 'i': $dividend = 60; //oSPHP.COM.CN break; case '
escape函數 /** * js escape php 實現 * @param $string the sting want to be escaped * @param $in_encoding * @param $out_encoding */ function escape($string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2') { $return = '';
很多時候我們需要對資料進行加密解密,比如有些資料需要儲存到cookie中,但又不能被使用者輕易得到這些資料,這時我們就需要加密這些資料儲存到cookie中,等我們需要使用它們的時候再解密。 // 加密資料並寫到cookie裡$cookie_data = $this -> encrypt("nowamagic", $data); $cookie = array( 'name' => '$data', 'value' => $cookie_data,
這段代碼非常有用,如果你下載了一個檔案,網站提供了hash結果,你可以對你下載下來的檔案進行hash運算,以驗證下載的檔案是否正確。 Hash (Check) Files if(!empty($_FILES)){ if ($_FILES["file"]["error"] > 0){ switch($_FILES["file"]["error"]){ case 1:
php中有一個擴充可以支援DES的密碼編譯演算法,是:extension=php_mcrypt.dll 在設定檔中將這個擴充開啟還不能夠在windows環境下使用 需要將PHP檔案夾下的 libmcrypt.dll 拷貝到系統的 system32 目錄下,這是通過phpinfo可以查看到mcrypt表示這個模組可以正常試用了。 下面是PHP中使用DES加密解密的一個例子: //$input - stuff to decrypt //$key - the secret