187 PHP字符過濾函數去除字符串最後一個逗號(rtrim)

轉自:https://www.jb51.net/article/35075.htm

首先分別解釋下,

trim過濾字符串兩端,
rtrim過濾字符串尾部,=chop()
ltrim過濾字符串首部.

過濾字符串中鍵的咚咚就只能用str_replace咯.
舉個例子說明下,

$str = '123,333,234,'; 
echo rtrim($str, ','); 
<?php
$text = "\t\tThese are a few words :) ...  ";
$trimmed = rtrim($text);
// $trimmed = "\t\tThese are a few words :) ..."
$trimmed = rtrim($text, " \t.");
// $trimmed = "\t\tThese are a few words :)"
$clean = rtrim($binary, "\x00..\x1F");
// trim the ASCII control characters at the end of $binary 
// (from 0 to 31 inclusive)
?>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章