note 111478 deleted from function.trim by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 12:17:10 +0000 |
| Subject: | note 111478 deleted from function.trim by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197140@lists.php.net to get a copy of this message | ||
Note Submitter: kafene
----
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
?>