php快速得到大數組裡的隨機小數組

有個猜使用者喜歡的功能,使用者可以通過點擊換一組,來重新整理推薦的內容。 先通過資料庫查詢,得到前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)

php實現簡單的文法高亮函數

一個php實現的簡單文法高亮顯示的函數,注意:這個函數設計的比較簡單,可能對某些文法不能高亮顯示,你可以自己擴充該函數的功能 function syntax_highlight($code){ // this matches --> "foobar" $code = preg_replace( '/"(.*?)"/U', '"$1"', $code ); // hightlight functions and

php通過socket post資料到其它web server

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') {

PHP根據圖片色界在不同位置加浮水印

PHP根據圖片色界在不同位置加浮水印 function add_wm($nmw_water, $src_file, $output_file, $x, $y) { if(file_exists($output_file)) return; $w1 = MagickGetImageWidth($nmw_water); $h1 =

php XSS安全過濾代碼

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*

一個php 產生zip檔案的類

/* By: Matt Ford Purpose: Basic class to create zipfiles */ class zipFile { public $files = array(); public $settings = NULL; public $fileInfo = array ( "name" => "", "numFiles" => 0,

php發送郵件函數,支援html和普通文本

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:

php檢測瀏覽器類型代碼

// 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 (

php編寫的簡單隨機抽獎函數

/** * “抽獎”函數 * * @param integer $first 起始編號 * @param integer $last 結束編號 * @param integer $total 獲獎人數 * * @return string **/function isWinner($first, $last, $total){ $winner = array(); for ($i=0;;$i++) { $number =

php返回相對時間,如:20分鐘前,3天前

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

php不破壞單詞截取子字串

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);

php MIME類型數組

這個數組包含了常見的MIME類型,如果你需要做檔案下載,可以通過這個數組查看副檔名,判斷是否可以下載 $mime_types = array("323" => "text/h323","acx" => "application/internet-property-stream","ai" => "application/postscript","aif" => "audio/x-aiff","aifc" => "audio/x-aiff","aiff" =>

php產生圓角圖片代碼

$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

360提供的php防注入代碼

//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|

php使用GD建立保持寬高比的縮圖

/** * 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 =

php隨機密碼產生器

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)

一個完整的圖片上傳php類

這個php圖片上傳類功能非常完善,完全可以滿足各種圖片上傳需求 /************************************** seesaw associates | http://seesaw.net client: file: description: Copyright (C) 2008 Matt Kenefick(.com)**************************************/ class mk_imageUpload{

php快速排序的演算法

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];

php計算兩個座標(經度,緯度)之間的距離

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

php動態處理圖片後輸出顯示

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

總頁數: 5203 1 .... 1690 1691 1692 1693 1694 .... 5203 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.