addslashes(); stripslashes(); //對(duì)數(shù)據(jù)庫(kù)教程操作時(shí),轉(zhuǎn)義特殊字符.

定義:addslashes() 函數(shù)在指定的預(yù)定義字符前添加反斜杠.

語(yǔ)法:addslashes(string)

注釋:默認(rèn)情況下,php 指令 magic_quotes_gpc 為 on,對(duì)所有的 get、post 和 cookie 數(shù)據(jù)自動(dòng)運(yùn)行 addslashes(),不要對(duì)已經(jīng)被 magic_quotes_gpc 轉(zhuǎn)義過(guò)的字符串使用 addslashes(),因?yàn)檫@樣會(huì)導(dǎo)致雙層轉(zhuǎn)義,遇到這種情況時(shí)可以使用函數(shù) get_magic_quotes_gpc() 進(jìn)行檢測(cè),代碼如下:

  1. <?php 
  2. function addslashes_str($str){ 
  3. $str=addslashes($str); 
  4. $str=str_replace($str,";",';'); 
  5. return $str
  6. }//開(kāi)源軟件:phpfensi.com 
  7. function stripslashes_str($str){ 
  8. $str=stripslashes($str); 
  9. $str=str_replace($str,';',";"); 
  10. return $str
  11. ?> 
  12.  chop(); //除去字符串右邊空格 
  13.  trim(); //除去字符串中所有空格 
  14.  ltrim(); //除去字符串左邊空格   
  15.  htmlspecialchars(); //轉(zhuǎn)換'$','"','<','>'為相應(yīng)的html實(shí)體 
  16.  htmlentities(); //轉(zhuǎn)換所有html標(biāo)記為相應(yīng)的html實(shí)體  
  17.  array explode(string separator, string str); //分割字符串 
  18.  string implode(string separator, array arr); //連接字符串 
  19.  strtoupper(); strtolower(); //轉(zhuǎn)換大小寫 
  20.  ucfirst(); //只轉(zhuǎn)換第一個(gè)字符為大寫  
  21.  ucwords(); //轉(zhuǎn)換每個(gè)words的第一個(gè)字母為大寫 

iconv()

php內(nèi)碼轉(zhuǎn)換函數(shù),同上,因?yàn)閕conv()在轉(zhuǎn)換gb2312時(shí)的bug,所以要這樣處理:

iconv( "utf-8", "gb2312//ignore" , $str)

mb_convert_encoding()

php的內(nèi)碼轉(zhuǎn)換函數(shù),版本(php 4 >= 4.0.6,php 5)

這個(gè)函數(shù)可以將各種編碼互相轉(zhuǎn)換
mb_convert_encoding($str,"gb2312", "utf-8");

mysql_real_escape_string()

定義:函數(shù)轉(zhuǎn)義 sql 語(yǔ)句中使用的字符串中的特殊字符

語(yǔ)法:mysql_real_escape_string(string,connection)

說(shuō)明:本函數(shù)將 string 中的特殊字符轉(zhuǎn)義,并考慮到連接的當(dāng)前字符集,因此可以安全用于 mysql_query().

轉(zhuǎn)載請(qǐng)注明來(lái)源:php過(guò)濾字符串函數(shù)

  哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無(wú)需額外費(fèi)用,即可穩(wěn)步提升排名至首頁(yè)。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)