note 71257 deleted from function.trim by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 12:24:22 +0000 |
| Subject: | note 71257 deleted from function.trim by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189648@lists.php.net to get a copy of this message | ||
Note Submitter: asbo/at\iserv/dot\net
----
If you need to trim a string from the beginning and end of a string, then this function maybe prove
handy.
<?php
function lrclean($str,$rm) {
$i = strlen($rm);
do {
if (substr($str,0,$i) == $rm) {$str = substr($str,$i);}
} while (substr($str,0,$i) == $rm);
do {
if (substr($str,-$i,$i) == $rm) {$str = substr($str,0,-$i);}
} while (substr($str,-$i,$i) == $rm);
return $str;
}
// prints 'text'
echo lrclean('xyztextxyz','xyz');
?>