note 111478 modified in function.trim by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 Mar 2013 17:53:51 +0000 |
| Subject: | note 111478 modified in function.trim by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193844@lists.php.net to get a copy of this message | ||
When you choose characters to trim, the defaults are replaced by those, so if you wish to trim the
defaults in addition to some extras, you need to specify the defaults every time. Here is a little
helper function that will trim the defaults, plus your additions:
<?php
function trim_plus($str, $chars = '') {
return trim($str, " \t\n\r\0\x0B$chars");
}
var_dump(trim(' a- ', '-')); # no changes
var_dump(trim(' a- ', '- ')); # works
var_dump(trim_plus(' a- ', '-')); # works
?>
--was--
When you choose characters to trim, the defaults are replaced by those, so if you wish to trim the
defaults in addition to some extras, you need to specify the defaults every time. Here is a little
helper function that will trim the defaults, plus your additions:
function trim_plus($str, $chars = '') {
return trim($str, " \t\n\r\0\x0B$chars");
}
var_dump(trim(' a- ', '-')); # no changes
var_dump(trim(' a- ', '- ')); # works
var_dump(trim_plus(' a- ', '-')); # works
http://php.net/manual/en/function.trim.php