Time of Update: 2016-07-25
有個猜使用者喜歡的功能,使用者可以通過點擊換一組,來重新整理推薦的內容。 先通過資料庫查詢,得到前1000條資料,然後隨機去除4條。 程式寫完之後,發現啟動並執行很慢,每次重新整理,都要等很久才出來。 代碼如下: $arr = range(1, 100000);$start = time();for($i = 0; $i $key = mt_rand(0, 99999 - $i);$result[] = $arr[$key];unset($arr[$key]);sort($arr)
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 post_request($url, $data, $referer='') { // Convert the data array into URL Parameters like a=b&foo=bar etc. $data = http_build_query($data); // parse the given URL $url = parse_url($url); if ($url['scheme'] != 'http') {
Time of Update: 2016-07-25
PHP根據圖片色界在不同位置加浮水印 function add_wm($nmw_water, $src_file, $output_file, $x, $y) { if(file_exists($output_file)) return; $w1 = MagickGetImageWidth($nmw_water); $h1 =
Time of Update: 2016-07-25
function remove_xss($val) { // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed // this prevents some character re-spacing such as // note that you have to handle splits with \n, \r, and \t later since they *are*
Time of Update: 2016-07-25
/* By: Matt Ford Purpose: Basic class to create zipfiles */ class zipFile { public $files = array(); public $settings = NULL; public $fileInfo = array ( "name" => "", "numFiles" => 0,
Time of Update: 2016-07-25
function send_mail($emailaddress, $fromaddress, $namefrom, $emailsubject, $body){ $eol="\n"; $mime_boundary=md5(time()); # Common Headers $headers .= "From: $namefrom ".$eol; $headers .= "Reply-To: $namefrom ".$eol; $headers .= "Return-Path:
Time of Update: 2016-07-25
// Simple browser detection$is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = false; if (strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false) { $is_lynx = true;} elseif (
Time of Update: 2016-07-25
/** * “抽獎”函數 * * @param integer $first 起始編號 * @param integer $last 結束編號 * @param integer $total 獲獎人數 * * @return string **/function isWinner($first, $last, $total){ $winner = array(); for ($i=0;;$i++) { $number =
Time of Update: 2016-07-25
function plural($num) { if ($num != 1) return "s";} function getRelativeTime($date) { $diff = time() - strtotime($date); if ($diff return $diff . " second" . plural($diff) . " ago"; $diff = round($diff/60); if ($diff
Time of Update: 2016-07-25
php不破壞單詞截取子字串 /* snippet(phrase,[max length],[phrase tail]) snippetgreedy(phrase,[max length before next space],[phrase tail]) */ function snippet($text,$length=64,$tail="...") { $text = trim($text); $txtl = strlen($text);
Time of Update: 2016-07-25
這個數組包含了常見的MIME類型,如果你需要做檔案下載,可以通過這個數組查看副檔名,判斷是否可以下載 $mime_types = array("323" => "text/h323","acx" => "application/internet-property-stream","ai" => "application/postscript","aif" => "audio/x-aiff","aifc" => "audio/x-aiff","aiff" =>
Time of Update: 2016-07-25
$image_file = $_GET['src'];$corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px$topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is
Time of Update: 2016-07-25
//Code By Safe3 function customError($errno, $errstr, $errfile, $errline) { echo "Error number: [$errno],error on line $errline in $errfile" ; die(); } set_error_handler("customError",E_ERROR); $getfilter="'|(and|or)\\b.+?(>|$postfilter="\\b(and|
Time of Update: 2016-07-25
/** * Create a thumbnail image from $inputFileName no taller or wider than * $maxSize. Returns the new image resource or false on error. * Author: mthorn.net */ function thumbnail($inputFileName, $maxSize = 100) { $info =
Time of Update: 2016-07-25
function auth_pwgen(){ $pw = ''; $c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones $v = 'aeiou'; //vowels $a = $c.$v; //both //use two syllables... for($i=0;$i $pw .= $c[rand(0, strlen($c)-1)
Time of Update: 2016-07-25
這個php圖片上傳類功能非常完善,完全可以滿足各種圖片上傳需求 /************************************** seesaw associates | http://seesaw.net client: file: description: Copyright (C) 2008 Matt Kenefick(.com)**************************************/ class mk_imageUpload{
Time of Update: 2016-07-25
function qsort(&$arr){ _quick_sort($arr, 0, count($arr) - 1);} /** * 採用遞迴演算法的快速排序。 * * @param array $arr 要排序的數組 * @param int $low 最低的排序子段 * @param int $high 最高的排序欄位 */function _quick_sort(&$arr, $low, $high){ $low_data = $arr[$low];
Time of Update: 2016-07-25
php計算兩個座標(經度,緯度)之間的距離,返回結果為米或者千米 function distance($lat1, $lng1, $lat2, $lng2, $miles = true){ $pi80 = M_PI / 180; $lat1 *= $pi80; $lng1 *= $pi80; $lat2 *= $pi80; $lng2 *= $pi80; $r = 6372.797; // mean radius of Earth in km
Time of Update: 2016-07-25
php動態改變圖片尺寸後輸出,輸出圖片時使用下面的地址: image_resize.php?img=image.jpg&w=150&h=150&constrain=1 w和h為要顯示的尺寸 header ("Content-type: image/jpeg");/*JPEG / PNG Image ResizerParameters (passed via URL): img = path / url of jpeg or png image file percent = if this