note 111478 added to function.trim

From: Date: Sat, 23 Feb 2013 15:33:07 +0000
Subject: note 111478 added to function.trim
Groups: php.notes 
Request: Send a blank email to php-notes+get-193737@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: 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 ---- Server IP: 69.147.83.199 Probable Submitter: 24.62.217.91 ---- Manual Page -- http://php.net/manual/en/function.trim.php Edit -- https://master.php.net/note/edit/111478 Del: integrated -- https://master.php.net/note/delete/111478/integrated Del: useless -- https://master.php.net/note/delete/111478/useless Del: bad code -- https://master.php.net/note/delete/111478/bad+code Del: spam -- https://master.php.net/note/delete/111478/spam Del: non-english -- https://master.php.net/note/delete/111478/non-english Del: in docs -- https://master.php.net/note/delete/111478/in+docs Del: other reasons-- https://master.php.net/note/delete/111478 Reject -- https://master.php.net/note/reject/111478 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193737) next »