note 95802 added to function.rtrim
| From: | pinkgothic at gmail dot com | Date: | Fri, 22 Jan 2010 13:36:42 +0000 |
| Subject: | note 95802 added to function.rtrim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165207@lists.php.net to get a copy of this message | ||
I have an obsessive love for php's array functions given how extremely easy they've made
complex string handling for me in various situations... so, have another string-rtrim() variant:
<?php
function strrtrim($message, $strip) {
// break message apart by strip string
$lines = explode($strip, $message);
$last = '';
// pop off empty strings at the end
do {
$last = array_pop($lines);
} while (empty($last));
// re-assemble what remains
return implode($strip, array_merge($lines, array($last)));
}
?>
Astonishingly, something I didn't expect, but: It completely compares to harmor's rstrtrim
below, execution time wise. o_o Whee!
----
Server IP: 85.214.154.209
Probable Submitter: 80.153.202.193
----
Manual Page -- http://www.php.net/manual/en/function.rtrim.php
Edit -- https://master.php.net/note/edit/95802
Del: integrated -- https://master.php.net/note/delete/95802/integrated
Del: useless -- https://master.php.net/note/delete/95802/useless
Del: bad code -- https://master.php.net/note/delete/95802/bad+code
Del: spam -- https://master.php.net/note/delete/95802/spam
Del: non-english -- https://master.php.net/note/delete/95802/non-english
Del: in docs -- https://master.php.net/note/delete/95802/in+docs
Del: other reasons-- https://master.php.net/note/delete/95802
Reject -- https://master.php.net/note/reject/95802
Search -- https://master.php.net/manage/user-notes.php