note 92299 added to function.trim
| From: | linuxmanmikec at gmail dot com | Date: | Fri, 17 Jul 2009 23:09:38 +0000 |
| Subject: | note 92299 added to function.trim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158442@lists.php.net to get a copy of this message | ||
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./@#\$");
?>
----
Server IP: 64.71.164.2
Probable Submitter: 67.88.116.250
----
Manual Page -- http://www.php.net/manual/en/function.trim.php
Edit -- https://master.php.net/note/edit/92299
Del: integrated -- https://master.php.net/note/delete/92299/integrated
Del: useless -- https://master.php.net/note/delete/92299/useless
Del: bad code -- https://master.php.net/note/delete/92299/bad+code
Del: spam -- https://master.php.net/note/delete/92299/spam
Del: non-english -- https://master.php.net/note/delete/92299/non-english
Del: in docs -- https://master.php.net/note/delete/92299/in+docs
Del: other reasons-- https://master.php.net/note/delete/92299
Reject -- https://master.php.net/note/reject/92299
Search -- https://master.php.net/manage/user-notes.php