php去除字串中Null 字元的常用方法小結
這篇文章主要介紹了php去除字串中Null 字元的常用方法,執行個體分析了php中的trim()、ltrim()、rtrim()及chop()等函數的提示,非常具有實用價值,需要的朋友可以參考下
本文執行個體總結了php去除字串中Null 字元的常用方法。分享給大家供大家參考。具體分析如下:
php中包含四個可以去除字串空格的函數:
trim() – 去除字串兩端的Null 字元
ltrim() – 去除字串前端的Null 字元
rtrim() – 去除字串末尾的Null 字元
chop() –同rtrim().
代碼如下:
?
| 1 2 3 4 5 6 7 8 9 |
$text = "\t \t jb51.net!\t \t "; $leftTrimmed = ltrim($text); $rightTrimmed = rtrim($text); $bothTrimmed = trim($text); print("leftTrimmed = ($leftTrimmed)\n"); print("rightTrimmed = ($rightTrimmed)\n"); print("bothTrimmed = ($bothTrimmed)\n"); ?> |
輸出結果:
?
| 1 2 3 |
leftTrimmed = (jb51.net! ) rightTrimmed = ( jb51.net!) bothTrimmed = (jb51.net!) |
希望本文所述對大家的php程式設計有所協助。
http://www.bkjia.com/PHPjc/969355.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/969355.htmlTechArticlephp去除字串中Null 字元的常用方法小結 這篇文章主要介紹了php去除字串中Null 字元的常用方法,執行個體分析了php中的trim()、ltrim()、rtrim()及ch...