php中常用字串處理函數_PHP教程

來源:互聯網
上載者:User
下面只提供幾個簡單常用的函數,chop執行去除空格處理,get_html_translation_table返迴轉化列表到變數,定義包括HTML編碼的字串htmlentities,htmlspecialchars_decode 定義包含HTML特殊字元的字串,nl2br quotemeta rtrim等。

下面只提供幾個簡單常用的函數,chop執行去除空格處理,get_html_translation_table返迴轉化列表到變數,定義包括html編碼的字串htmlentities,htmlspecialchars_decode 定義包含html特殊字元的字串,nl2br quotemeta rtrim等。
定義和用法
chop() 函數從字串的末端開始刪除空白字元或其他預定義字元。

該函數的 rtrim() 函數的別名。

文法

chop(string,charlist)

*/
$str="i'm a teacher "; //定義字串
$result=chop($str); //執行去除空格處理
echo $result; //輸出結果

/*/

定義和用法
get_html_translation_table() 函數返回被 htmlentities() 和 htmlspecialchars() 函數使用的翻譯表。

文法
get_html_translation_table(function,quotestyle)

/*/
$trans=get_html_translation_table(html_entities); //返迴轉化列表到變數
print_r($trans); //輸出轉換表
$str="hallo & & krmer"; //定義字串
$encoded=strtr($str,$trans); //尋找字元
echo $encoded; //輸出結果
//

$str="a 'quote' is bold"; //定義包括html編碼的字串
echo htmlentities($str); //輸出經過處理的字串
echo htmlentities($str, ent_quotes); //加上選擇性參數後的輸出結果

//
$str='

this -> "

'; //定義包含html特殊字元的字串
echo htmlspecialchars_decode($str); //輸出轉換後的內容
echo "
";
echo htmlspecialchars_decode($str,ent_noquotes); //不對引號進行編碼的輸出結果

//

$str="cat isn't n dog"; //定義包含分行符號的字串
$result=nl2br($str); //執行轉換操作
echo $result; //輸出轉換後的結果

//

$str="hello world.(can you hear me?)"; //定義包含元字元的字串
$result=quotemeta($str); //執行轉換操作
echo $result; //輸出轉換後的結果

//

$str="hello world "; //定義末尾有空格的字串
$result=rtrim($str); //執行轉換操作
echo $result; //輸出轉換後的結果
?>


http://www.bkjia.com/PHPjc/445386.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445386.htmlTechArticle下面只提供幾個簡單常用的函數,chop執行去除空格處理,get_html_translation_table返迴轉化列表到變數,定義包括HTML編碼的字串htmlentities,...

  • 聯繫我們

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