說明:移除字串首尾的空白字元。
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()。