note 95802 modified in function.rtrim by danbrown

From: Date: Tue, 16 Feb 2010 18:02:36 +0000
Subject: note 95802 modified in function.rtrim by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166017@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) && (count($lines))); // 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! --was-- 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! http://php.net/manual/en/function.rtrim.php

« previous php.notes (#166017) next »