Time of Update: 2016-07-25
一個php實現的簡單文法高亮顯示的函數,注意:這個函數設計的比較簡單,可能對某些文法不能高亮顯示,你可以自己擴充該函數的功能 function syntax_highlight($code){ // this matches --> "foobar" $code = preg_replace( '/"(.*?)"/U', '"$1"', $code ); // hightlight functions and
Time of Update: 2016-07-25
function copy_dir($src,$dst) { $dir = opendir($src); @mkdir($dst); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) {
Time of Update: 2016-07-25
這段php代碼可以把一個顏色變成與之相反的顏色編碼,如:白色變成黑色,藍色變成黃色 function color_inverse($color){ $color = str_replace('#', '', $color); if (strlen($color) != 6){ return '000000'; } $rgb = ''; for ($x=0;$x $c = 255 - hexdec(substr($color,(2*$x),2));
Time of Update: 2016-07-25
/** * 截取字串 * params $string 要截取的字串 * params $length: 保留長度(字元數) * params $dot: 多餘部分顯示**/function _cutstr($string, $length, $dot = ' ...') { if(strlen($string) return $string; } $string = str_replace(array('&', '"', ''), array('&',
Time of Update: 2016-07-25
/** * 通用加密 * @param String $string 需要加密的字串 * @param String $skey 加密EKY * @return String */function enCode($string = '', $skey = 'echounion') { $skey = array_reverse(str_split($skey)); $strArr = str_split(base64_encode($string)); $strCount =
Time of Update: 2016-07-25
function inject_check($sql_str) { return eregi('select|insert|and|or|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile', $sql_str);} function verify_id($id=null) { if(!$id) { exit('沒有提交參數!'); } elseif(inject_check($
Time of Update: 2016-07-25
對於zip檔案網上的例子很多,rar檔案解壓php沒有直接支援,可以用pecl 到http://pecl.php.net/package/rar 下載對應版本的 非安全執行緒的dll 然後扔到php的 ext目錄下。 開啟php.ini. 加一行 extension=php_rar.dll 重啟web伺服器 和php public function _unzip($fileName,$extractTO){
Time of Update: 2016-07-25
/** * +-------------------------------------------------------------------- * Description 遞迴刪除目錄 +-------------------------------------------------------------------- * @param string $dir 需要刪除的目錄 +----------------------------------------------------
Time of Update: 2016-07-25
function compress_html($string) { $string = str_replace("\r\n", '', $string); //清除分行符號 $string = str_replace("\n", '', $string); //清除分行符號 $string = str_replace("\t", '', $string); //清除定位字元 $pattern = array ( "/> *([^ ]*
Time of Update: 2016-07-25
/** * +-------------------------------------------------------------------- * Description 遞迴建立目錄 +-------------------------------------------------------------------- * @param string $dir 需要創新的目錄 +----------------------------------------------------
Time of Update: 2016-07-25
通過php的 similar_text函數比較兩個字串的相似性 $word2compare = "stupid"; $words = array( 'stupid', 'stu and pid', 'hello', 'foobar', 'stpid', 'upid', 'stuuupid', 'sstuuupiiid',); while(list($id, $str) = each($words)){ similar_text($str,
Time of Update: 2016-07-25
function getfirstchar($s0) {$fchar = ord(substr($s0, 0, 1));if (($fchar >= ord("a") and $fchar = ord("A") and $fchar $s = iconv("UTF-8", "gb2312", $s0);$asc = ord($s{0}) * 256 + ord($s小貝)-65536;if ($asc >= -20319 and $asc if ($asc >= -20283 and $asc
Time of Update: 2016-07-25
這個php函數可以把指定的顏色變得更深一些 function ColorDarken($color, $dif=20){ $color = str_replace('#', '', $color); if (strlen($color) != 6){ return '000000'; } $rgb = ''; for ($x=0;$x $c = hexdec(substr($color,(2*$x),2)) - $dif; $c =
Time of Update: 2016-07-25
function getPicture($url,$pictureName){if ($url == "") return false;//擷取圖片的副檔名$info = getimagesize($url);$mime = $info['mime'];$type = substr(strrchr($mime,'/'), 1);//不同的圖片類型選擇不同的圖片產生和儲存函數switch($type){case 'jpeg':$img_create_func =
Time of Update: 2016-07-25
function show_page($count,$page,$page_size){$page_count = ceil($count/$page_size); //計算得出總頁數$init=1;$page_len=7;$max_p=$page_count;$pages=$page_count;//判斷當前頁碼$page=(empty($page)||$page//擷取當前頁url$url =
Time of Update: 2016-07-25
function quicksortX(&$seq){ $stack = array($seq); $sort = array(); while ($stack) { $arr = array_pop($stack); if(count($arr) if (count($arr) == 1) { $sort[] = &$arr[0]; }
Time of Update: 2016-07-25
php計算串連的mysql資料庫的大小,用MB,KB或者GB的格式返回 function CalcFullDatabaseSize($database, $db) { $tables = mysql_list_tables($database, $db); if (!$tables) { return -1; } $table_count = mysql_num_rows($tables); $size = 0; for ($i=0; $i
Time of Update: 2016-07-25
function num_format($num){if(!is_numeric($num)){return false;}$rvalue='';$num = explode('.',$num);//把整數和小數分開$rl = !isset($num['1']) ? '' : $num['1'];//小數部分的值$j = strlen($num[0]) % 3;//整數有多少位$sl = substr($num[0], 0, $j);//前面不滿三位的數取出來$sr = substr($num[
Time of Update: 2016-07-25
function dirSize($directoty){$dir_size=0;if($dir_handle=@opendir($directoty)){while($filename=readdir($dir_handle)){$subFile=$directoty.DIRECTORY_SEPARATOR.$filename;if($filename=='.'||$filename=='..'){continue;}elseif
Time of Update: 2016-07-25
實現原理先算出該點周圍的矩形的四個點,然後使用經緯度去直接匹配資料庫中的記錄。 //擷取周圍座標 public function returnSquarePoint($lng, $lat,$distance = 0.5){ $earthRadius = 6378138; $dlng = 2 * asin(sin($distance / (2 * $earthRadius)) / cos(deg2rad($lat))); $dlng =