Time of Update: 2016-07-25
$array = array('A','2','3','4','5','6','7','8','9','10','J','Q','K'); shuffle($array); //隨機排序數組 print_r($array); //輸出數組 ?> 複製代碼>>> 您可能感興趣的文章:php關聯陣列排序、快速排序的執行個體分享php二維數組排序(執行個體)PHP數組排序方法總結(收藏)php 二維數組排序的兩個例子php
Time of Update: 2016-07-25
$pagesize=10; //設定每一頁顯示的記錄數$conn=mysql_connect("localhost","root",""); //串連資料庫$rs=mysql_query("select count(*) from tb_product",$conn); //取得記錄總數$rs$myrow = mysql_fetch_array($rs);$numrows=$myrow[0];//計算總頁數$pages=intval($numrows/$pagesize);//判斷頁數設定if
Time of Update: 2016-07-25
本文介紹下php編程中正則過濾特殊字元的方法,有需要的朋友參考下。在php中用Regex過濾特殊字元,可以使用函數preg_quote:string preg_quote( string $str[, string $delimiter] )找出$str字串中出現的屬於Regex的特殊字元,並在改特殊字元前面加上一個反斜線。可以提供一個可選的$delimiter字串參數作為新增的逸出字元集合。Regex的特殊字元包括: . \ + * ? [ ^ ] $ ( ) { } = ! | :
Time of Update: 2016-07-25
$content=file_get_contents("myfile.txt");$array = explode("\r\n", $content);$data =array();foreach ($array as $row) { $data[] = explode("||", $row);}for($i=0;$i$a=$data[$i][0];$b=$data[$i][1];echo "$a && $b
Time of Update: 2016-07-25
$str=preg_replace("/\s+/", " ", $str); //過濾多餘斷行符號 $str=preg_replace("//si","",$str); //注釋 $str=preg_replace("//si","",$str); //過濾DOCTYPE $str=preg_replace("//si","",$str); //過濾html標籤 $str=preg_replace("//si","",$str); //過濾br標籤
Time of Update: 2016-07-25
/** * csv_get_lines 讀取CSV檔案中的某幾行資料 * @param $csvfile csv檔案路徑 * @param $lines 讀取行數 * @param $offset 起始行數 * @return array * */ bbs.it-home.orgfunction csv_get_lines($csvfile, $lines, $offset = 0) { if(!$fp = fopen($csvfile, 'r')) { return false;
Time of Update: 2016-07-25
!extension_loaded('curl') && die('the curl extension is not loaded.'); $baseurl = 'http://127.0.0.1';//根地址 $login_url = $baseurl .'/login.php?act=login';//登入頁地址 $get_url = $baseurl .'/index.php'; //需要採集的頁面 $post_fields = array();
Time of Update: 2016-07-25
本文介紹了php中特殊字元轉義的相關函數的用法,掌握下php處理特殊字元的方法,有需要的朋友參考下。mysql和php內建很多函數可以處理字元問題,下面給出幾個會經常用到的.ps:由於php6開始不支援magic_quotes_gpc,所以下面的東西都是假設在magic_quotes_gpc=off的條件上(不知道php6會出什麼新東西....)mysql_real_escape_string()定義:函數轉義 sql 語句中使用的字串中的特殊字元。文法:
Time of Update: 2016-07-25
function reversr_r($str){if (strlen($str)>0)reverse_r(substr($str,1));echo substr($str,0,1);return;}?>function reverse_i($str){for($i=1;$i{echo
Time of Update: 2016-07-25
if(phpversion() set_magic_quotes_runtime(0); }複製代碼>> 無法通過函數來定義magic_quotes_gpc,因此建議在伺服器上統一開啟,寫程式的時候應該在來判斷下,避免沒開啟gpc引起安全問題 通過addslashes對gpc進行時候轉義時,應注意當使用者提交數組資料時對索引值和值的過濾 if(!get_magic_quotes_gpc()) { $_get = daddslashes($_get); $_post = daddslashes(
Time of Update: 2016-07-25
/*** 擷取用戶端ip* @return [string] [description]*/function getclientip() {$ip = null;if (isset($_server['http_x_forwarded_for'])) {$arr = explode(',', $_server['http_x_forwarded_for']);$pos = array_search('unknown',$arr);if(false !== $pos)
Time of Update: 2016-07-25
[mysql] default-character-set=utf8 [mysqld] default-character-set=utf8 default-storage-engine=myisam 在[mysqld]下加入: default-collation=utf8_bin init_connect='set names utf8'複製代碼2.在需要做資料庫操作的php程式前加mysql_query("set names '編碼'");,編碼和php編碼一致,如果php編碼是gb2312
Time of Update: 2016-07-25
關於如何才能成為一名優秀的程式員,最近又一次成為了我們關注的焦點。下面是我認為我們最需要具備的特質:善於解決問題。既發奮又懶惰。能理解別人的代碼。對編程充滿熱情。為了學習而愛上學習。擅長數學。具有良好的溝通技巧。強大的辯論技巧。極端樂觀。極度悲觀。1.善於解決問題——希望大家都能認識到這一點。大多數優秀的程式員能夠找到別人發現不了的解決方案。2.既發奮又懶惰——這一點讓很多人都感到吃驚。程式員之所以喜歡提出質疑,往往是因為“懶得”走冤枉路。在這種想法的驅使下,他們會孜孜不倦地簡化問題,簡化任務。
Time of Update: 2016-07-25
preg_replace(”/([\x80-\xff])/”,”",$str); preg_replace(”/([u4e00-u9fa5])/”,”",$str);複製代碼例子,php中文編碼判斷。 //判斷內容裡有沒有中文-gbk (php) function check_is_chinese($s){ return preg_match('/[\x80-\xff]./', $s); } //擷取字串長度-gbk (php) function gb_strlen($str){ $count
Time of Update: 2016-07-25
function quick_sort($array) { if(count($array) $key = $array[0]; $rightArray = array(); $leftArray = array(); for($i = 1; $i if($array[$i] >= $key) { $rightArray[] = $array[$i]; } else { $leftArray[] = $array[$i]; } } $leftArray =
Time of Update: 2016-07-25
/** * 資料編碼轉換 * @param array/string $data 數組 * @param string $output 轉換後的編碼 */function array_iconv($data,$output = 'utf-8') { $encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP'); $encoded =
Time of Update: 2016-07-25
//字串截取$a = "s@@你好";var_dump(strlen_weibo($a,'utf-8'));結果輸出為8,其中字母s計數為1,全形@計數為2,半形@計數為1,兩個中文計數為4。源碼如下://截取字串的函數代碼function strlen_weibo($string, $charset='utf-8'){ $n = $count = 0; $length = strlen($string); if (strtolower($charset) == 'utf-8'
Time of Update: 2016-07-25
class gb2utf8 { var $gb; // 待轉換的gb2312字串 var $utf8; // 轉換後的utf8字串 var $codetable; // 轉換過程中使用的gb2312代碼檔案數組 var $errormsg; // 轉換過程之中的錯誤訊息 function gb2utf8($instr="") { $this->gb=$instr; $this->setgb2312(); ($this->gb=="")?0:$this->convert();
Time of Update: 2016-07-25
/*** 添加背景* @param string $src 圖片路徑* @param int $w 背景映像寬度* @param int $h 背景映像高度* @return 返回加上背景的圖片* **/public function addBg($src,$w,$h){$bg = imagecreatetruecolor($w,$h);$white =
Time of Update: 2016-07-25
header("content-type: text/html; charset=utf-8");echo mb_convert_encoding("妳係我的友仔", "utf-8", "gbk");?> 複製代碼gb2312 to big5編碼轉換: header("content-type: text/html; charset=big5");echo mb_convert_encoding("你是我的朋友", "big5", "gb2312");?>