note 106406 added to function.trim
| From: | JesseOberlin at osu1 dot php dot net | Date: | Tue, 08 Nov 2011 02:37:56 +0000 |
| Subject: | note 106406 added to function.trim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184321@lists.php.net to get a copy of this message | ||
trim_chars
(trim string or character off beginning and end of a string)
function trim_chars($string,$char,$whitespace_first=null){
$string = ($whitespace_first ? trim($string) : $string);
$trimmed = ( substr($string,-1)==$char ? substr($string,($string[0]==$char ? 1 : 0),-1) :
substr($string,($string[0]==$char ? 1 : 0)) );
return ( $trimmed == $string ? $trimmed : trim_str($trimmed,$char) );
}
usage:
echo trim_chars('&%$abc&%$', '&%$');
echo trim_chars(' &%$abc&%$ ', '&%$', true);
echo trim_chars(' %%%abc%%% ', '&%$', false);
echo trim_chars('&%$abc&%$ ', '&%$', false);
outputs:
'abc'
'abc'
' &%$abc&%$ '
'abc&%$ '
----
Server IP: 69.147.83.197
Probable Submitter: 75.187.206.218
----
Manual Page -- http://www.php.net/manual/en/function.trim.php
Edit -- https://master.php.net/note/edit/106406
Del: integrated -- https://master.php.net/note/delete/106406/integrated
Del: useless -- https://master.php.net/note/delete/106406/useless
Del: bad code -- https://master.php.net/note/delete/106406/bad+code
Del: spam -- https://master.php.net/note/delete/106406/spam
Del: non-english -- https://master.php.net/note/delete/106406/non-english
Del: in docs -- https://master.php.net/note/delete/106406/in+docs
Del: other reasons-- https://master.php.net/note/delete/106406
Reject -- https://master.php.net/note/reject/106406
Search -- https://master.php.net/manage/user-notes.php