php 過濾字串函數

來源:互聯網
上載者:User

<? nl2br(); // to <br/>

 addslashes(); strips教程lashes(); //對資料庫教程操作時,轉義特殊字元
定義: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;
}
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)
這個函數可以將各種編碼互相轉換
mb_convert_encoding($str,"gb2312", "utf-8");


mysql教程_real_escape_string()
定義:函數轉義 sql 語句中使用的字串中的特殊字元。
文法: mysql_real_escape_string(string,connection)
說明:本函數將 string 中的特殊字元轉義,並考慮到串連的當前字元集,因此可以安全用於 mysql_query()。
 ?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.