Re: [PHP-DEV] string replacement From: Jan Borsodi (jb <email protected>)
Date: 01/22/01

Cynic <cynic <email protected>> writes:

> so it's probably not str_replace what's slowing you down, but
> the loops? Maybe they could be optimized some more... (I don't
> want it sound like I'm saying it's your fault, or that you're
> a bad programmer, just to make it clear.)

No it's not the loops it's just PHP being as slow as it always is.

The loop looks something like this:
$str = "lots of text";
$arr = array( "a", "b", "c", "d" );
$vals = array( "e", "f", "g", "h" );
$a =& each( $arr );
$b =& each( $vals );
while( $a && $b )
{
    str =& str_replace( $a[1], $b[1], $str );
    $a =& each( $arr );
    $b =& each( $vals );
}

Anyways this is beyond the point which is that these three functions
(str_replace, ereg_replace and preg_replace) does the same things but
varying complexity, but their usage is not the same. This is just a
matter of consistency amongst functions.
When I want to replace a simple string with another string I use
str_replace, when I want to replace a regular expression with a string
I use ereg_replace or preg_replace. However when I want replace lots
of simple strings I must use preg_replace due to speed. This is not
good.

So I ask again:
Are there any plans to make str_replace and ereg_replace take arrays
as parameters as well, in the same manner as preg_replace does?
(a simple yes or no will suffice)

Or do I have to do this myself?

-- 
- Jan Borsodi <jb <email protected>> - Systems Engineer @ eZ systems - Web: http://ez.no
  QtVu: http://www.qtvu.org  -  RegExplorer: http://regexplorer.sourceforge.net
  EMacro: http://emacro.sourceforge.net  -  Apollo: http://www.apolloplayer.org

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>