addslashes(); stripslashes(); //對數據庫教程操作時,轉義特殊字符.
定義:addslashes() 函數在指定的預定義字符前添加反斜杠.
語法:addslashes(string)
注釋:默認情況下,php 指令 magic_quotes_gpc 為 on,對所有的 get、post 和 cookie 數據自動運行 addslashes(),不要對已經被 magic_quotes_gpc 轉義過的字符串使用 addslashes(),因為這樣會導致雙層轉義,遇到這種情況時可以使用函數 get_magic_quotes_gpc() 進行檢測,代碼如下:
- <?php
- function addslashes_str($str){
- $str=addslashes($str);
- $str=str_replace($str,";",';');
- return $str;
- }//開源軟件:Vevb.com
- function stripslashes_str($str){
- $str=stripslashes($str);
- $str=str_replace($str,';',";");
- return $str;
- }
- ?>
- chop(); //除去字符串右邊空格
- trim(); //除去字符串中所有空格
- ltrim(); //除去字符串左邊空格
- htmlspecialchars(); //轉換'$','"','<','>'為相應的html實體
- htmlentities(); //轉換所有html標記為相應的html實體
- array explode(string separator, string str); //分割字符串
- string implode(string separator, array arr); //連接字符串
- strtoupper(); strtolower(); //轉換大小寫
- ucfirst(); //只轉換第一個字符為大寫
- ucwords(); //轉換每個words的第一個字母為大寫
iconv()
php內碼轉換函數,同上,因為iconv()在轉換gb2312時的bug,所以要這樣處理:
iconv( "utf-8", "gb2312//ignore" , $str)
mb_convert_encoding()
php的內碼轉換函數,版本(php 4 >= 4.0.6,php 5)
mysql_real_escape_string()
定義:函數轉義 sql 語句中使用的字符串中的特殊字符
語法:mysql_real_escape_string(string,connection)
說明:本函數將 string 中的特殊字符轉義,并考慮到連接的當前字符集,因此可以安全用于 mysql_query().
新聞熱點
疑難解答