Re: how to post a question?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey Rich,

> > The str_replace calls are kinda expensive IMHO, a good regex would be
> > better

> I'd be interested to see a benchmark (any benchmark) where str_replace is
> SLOWER than the corresponding Regex...

I am not very good with RegEx's myself, and I have never benchmarked any of
them but
I was told or read (when i first started learning php) that using multiple
str_replace()s are
not a good idea and to use a regex instead.
(Thats why I wrote the "IMHO",if i was wrong one of the gurus here could
correct me)

It kind of makes sense, for example using this from the php site:

$phrase  = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy  = array("pizza", "beer", "ice cream");

$newphrase = str_replace($healthy, $yummy, $phrase);

in the above, first it searches the entire phrase for the first parameter
(fruits) then it starts
again fro the second parameter (vegetables) etc, if you have a really long
text it could
be quite process intensive....because it would have to go through the whole
text searching for
the parameters one by one....right?

You're the guy who usually helps me (and a whole lot of others) when we have
questions
so I am really interested on your view on this, and why your view favours
one side more than
the other.

Cheers,
Ryan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux