本文介紹了php5中常有的字串處理函數,包括字串比較,字串尋找,字串截取等函數,有需要的朋友參考下。php5字串處理函數小結,使用php編程的朋友可以做個參考。php常用字串處理函數(字串比較,字串尋找,字串截取等),如下:addcslashes — 為字串裡面的部分字元添加反斜線逸出字元 addslashes — 用指定的方式對字串裡面的字元進行轉義 bin2hex — 將位元據轉換成十六進位表示 chop — rtrim() 的別名函數 chr — 返回一個字元的ascii碼
$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標籤
$size = "old size"; //注意最後size變數的值。 $a = array( "color" => "red", "size" => "XXL", "price" => "53"); extract($a); echo "color = $color"; echo "size = $size"; echo "price = $price"; ?> 複製代碼輸出結果: color = red size = XXL price =
複製代碼即可解決中文亂碼的問題,當然也可以修改charset=utf-8為charset=gb2312,根據自己的網頁編碼而定。php mysql表中文亂碼問題如何解決php匯入csv檔案中文亂碼的解決方案解決php
/** * class EfficiencyTester * 效率測試器,測試函數的已耗用時間 * @version 1.0 2013.04.13 * @author Kross */class EfficiencyTester { /** * var $testTimes * 測試的次數 */ private $testTimes = 1000; /** * function getTime() *
本文介紹了php中特殊字元轉義的相關函數的用法,掌握下php處理特殊字元的方法,有需要的朋友參考下。mysql和php內建很多函數可以處理字元問題,下面給出幾個會經常用到的.ps:由於php6開始不支援magic_quotes_gpc,所以下面的東西都是假設在magic_quotes_gpc=off的條件上(不知道php6會出什麼新東西....)mysql_real_escape_string()定義:函數轉義 sql 語句中使用的字串中的特殊字元。文法:
本文介紹了php字串整理的方法,包括訪問單個字元、刪除空白字元、html轉義等操作,有需要的朋友參考下。php實現字串中字元的訪問、整理字串以及字串的轉碼。1,訪問單個字元在php中,可以把字串當成一個字元的數組,可以直接用數組的存取方法來訪問字串。如$str[0]。在這裡要注意的是,如果字元是ascii碼以外時,訪問會有問題。因為這種訪問只能取得一個位元組。2,刪除空白字元在php中,可以用trim(), ltrim(), rtrim()三個函數來刪除字串開頭或結尾的空白字元。其中,trim(
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
本文介紹下php使用gd庫繪圖時,無法顯示圖片的原因與解決方案,有需要的朋友參考下。php繪圖,必需確認gd庫是否啟用,到php.ini檔案中,找到extension=php_gd2.dll將前面的;去掉,重新啟動伺服器。如果在繪圖中還是沒有顯示正常的圖片,說明伺服器在回複請求時,圖片的資訊有誤,要保證不要前面不要有任何東西,包括html。若還不出圖片,在繪圖前清一下緩衝(也就是在寫header之前),先寫ob_clean();
if(phpversion() set_magic_quotes_runtime(0); }複製代碼>> 無法通過函數來定義magic_quotes_gpc,因此建議在伺服器上統一開啟,寫程式的時候應該在來判斷下,避免沒開啟gpc引起安全問題 通過addslashes對gpc進行時候轉義時,應注意當使用者提交數組資料時對索引值和值的過濾 if(!get_magic_quotes_gpc()) { $_get = daddslashes($_get); $_post = daddslashes(
$fruits = array("Apple", "Banana", "Orange", "Pear", "Grape", "Lemon", "Watermelon");$subset = array_slice($fruits, 3);print_r($subset);// output// Array ( [0] => Pear [1] => Grape [2] => Lemon [3] => Watermelon )?> 複製代碼然後,使用下負長度: $fruits =
//方法一//過濾',",sql語名addslashes();//方法二,去除所有html標籤strip_tags();//方法三過濾可能產生代碼function php_sava($str) { $farr = array( "/s+/", "/]*?)>/isU",
#匯入PHP5的模組LoadModule php5_module "D:/Program Files/PHP/php5apache2_2.dll"#URL中能夠識別.php結尾的檔案AddType application/x-httpd-php .php#URL中能夠識別.phps結尾的檔案AddType application/x-httpd-php-source .phps#網站預設PHP得首頁DirectoryIndex index.html index.htm index.php
static function convert($size) { $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; }複製代碼2,php擷取檔案大小的方法二 /** * Returns a human readable filesize */function
/*** 擷取用戶端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)
/*** 作用:查詢所有分類產生Tree菜單* @param int $pid 父ID 預設從頂級開始查詢*/function toTree($pid=0){ //查詢所有頂級分類 //資料庫連接在此就不多說了 $model=M('Category');執行個體化模型 //查詢map條件 $map=array( 'pid'=>$pid, ); //查詢 $data=$model->where($map)->select(); //
header("content-type: text/html; charset=utf-8");header("cache-control: no-cache, must-revalidate"); header("pragma: no-cache");error_reporting(0);ob_end_flush();?>//加了這句,看看能不能解決linux下顯示亂碼的問題?php 探針 v1.0 - bbs.it-home.org著作權資訊[基本資料] [進階資訊]if
//特殊字元過濾function htmldecode($str) { if(empty($str)) return; if($str=="") return $str; $str=str_replace("&",chr(34),$str); $str=str_replace(">",">",$str); $str=str_replace("$str=str_replace("&","&",$str); $str=str_replace(" ",chr(32),$str);
$str = '1234567890';$needle = '234';$result = strchr($str, $needle);var_dump($result); 複製代碼結果:string '234567890'(length=9)strrpos尋找字串中某字元最後出現處。文法: int strrpos(string haystack,char needle);本函數用來尋找字串 haystack 中的字元 needle
rpm -ivh http://nginx.org/packages/centos/6/noarch/rpms/nginx-release-centos-6-0.el6.ngx.noarch.rpm複製代碼安裝epel源: (64位系統) rpm -ivh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm(32位系統) rpm -ivh