Re: [PHP4BETA] replacing a substring
| From: | Andrei Zmievski | Date: | Wed, 17 Nov 1999 21:35:36 +0000 |
| Subject: | Re: [PHP4BETA] replacing a substring | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-6399@lists.php.net to get a copy of this message | ||
On Wed, 17 Nov 1999, Lars Torben Wilson wrote:
> May I propose a change in the argument order for substr_replace()? At
> present, the argument list is:
>
> substr_replace($string, $start [, $length [, $repl]])
>
> The way it works now is effectively that if $length is not given,
> neither may $repl be given, and nothing is done. It seems that this
> order was chosen for its relationship to substr(). I think that it
> might make more sense to go with a closer relationship to
> str_replace(), and place the needle and the haystack closer
> together. This would allow $length to be left out without affecting
> $repl:
>
> substr_replace($string, $repl [, $start [, $length]])
The reason I did it is that people may want to omit the $repl,
effectively having substr_replace() remove a chunk of the string. I am
pretty flexible abou this, I just don't know how many people want it one
way or the other.
> Now, with this idea, the only problem is what $length should default
> to. Personally, I like it defaulting to 0, which just inserts $repl
> into $string at $start. However, it would be more consistent with
> substr() if $length defaulted to strlen( $string ), which would result
> in everything from $start to the end of $string being replaced. Come
> to think of if, perhaps strlen( $repl ) would make more sense.
Right now it defaults to the value that would remove anythin from the
offset to the end of the string. Once again, different people have
different opinions on what should be the default. I don't know exactly
how to gauge it.
-Andrei
* On the keyboard of life, always keep one finger on the escape key. *