note 92299 deleted from function.trim by danbrown
| From: | danbrown@php.net | Date: | Fri, 17 Jul 2009 23:14:36 +0000 |
| Subject: | note 92299 deleted from function.trim by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158443@lists.php.net to get a copy of this message | ||
Note Submitter: linuxmanmikec at gmail dot com
----
Andrew's chaining of trim below will not work as he thinks:
<?php
$str = trim(trim($str), './@#$');
?>
This will NOT trim whitespace AND the ./@#$ characters. First it will trim whitespace, then it will
trim the ./@#$ characters off that. So if you had a string
' $#sometext #$'
it would become
'sometext '.
You would end up with whitespace you thought you were getting rid of.
If you wish to specify characters in addition to what trim removes by default, you must specify ALL
characters you want trim to remove in a single call to trim.
<?php
$str = trim($str, " \t\n\r\0\x0B./@#\$");
?>