note 55929 deleted from function.str-replace by victor
| From: | victor@php.net | Date: | Thu, 18 Aug 2005 06:50:08 +0000 |
| Subject: | note 55929 deleted from function.str-replace by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93821@lists.php.net to get a copy of this message | ||
Note Submitter: mfdz dot com - address is jchris
----
This function recursively replaces multiple instances of the same character, taking it down to a
maximum of one. If you have say, a list of tags like (with a arbitrary number of spaces where you
want only one):
$tags = "php function string cleaning";
r_str_replace(" "," ",$tags);
will return a version with only one space between words, ie:
"php function string cleaning".
function r_str_replace($original, $replace, $string) {
$output = str_replace($original, $replace, $string, $count);
if ($count == 0) return $output;
$output = r_str_replace ($original, $replace ,$output);
return $output;
}