首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

PHP 4 手冊:函數 - trim

     編輯:PHP 相關知識

trim

說明:移除字串首尾的空白字元。

string trim(string str [, string charlist])

第二參數 PHP 4.1.0 新增。預設移除:空格 (0x20)、定位字元 (0x09)、換行 (0x0A)、歸位 (0x0D)、NULL (0x00)、垂直定位 (0x0B)。charlist 可自訂移除字元,支援 .. 範圍。

範例

$text = '  These are a few words :) ...  ';
$trimmed = trim($text);               // 'These are a few words :) ...'
$trimmed = trim($text, ' .');         // 'These are a few words :)'
$clean = trim($binary, "\x00..\x1F"); // 移除 ASCII 控制字元

相關:ltrim()、rtrim()。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved