First, there is no function called reg_replace(). It's ereg_replace().
str_replace() does not use regular expressions. It's a simple string-for-string replacement.
ereg_replace() and
pre_replace() both use something called regular expressions. A regular expression [
link to wikipdia article] does not match an exact string -- it describes in a general way a pattern within a string and attempts to match that. So str_replace() can match exactly "999", where ereg_replace() and preg_replace() can both match "any three numerical digits".
The difference between ereg_replace() and preg_replace() is the regular_expression engines each function uses. preg_replace() uses a perl-compatible regular expression engine and according to the PHP online manual is often faster than ereg_replace(). (see the tip
here). But str_replace(), since it does a simpler function, will be less resource-intensive than either of the other two.
As to which to use, there is no single universally appropriate function. If you need to do a simple string replacement use str_replace() as it's less resource-intensive. If you need to match a complex string that could vary but can be described in a general way, then use one of the regular expression functions. (I prefer preg_replace(), but others like ereg_replace()).
Want the best answers?
Ask the best questions!
TANSTAAFL!!