* Thus wrote Binay Agarwal ([EMAIL PROTECTED]): > Hi everybody, > > Lot of places in manual i came across using "ereg_replace" or "ereg" is very > resource intensive and hence its better to use "preg_replace" or "str_replace" or > "strpos" if they do the jobs. >
I believe the use of ereg_replace in the samples you see is mainly due to the fact that not until recently has preg_* function been enabled by default. So it would make sense for the manual to use examples with ereg_* functions so the example would be garuenteed to work. I would even suggest someone to use str_replace over preg_replace. The fact being that anytime you call a regular expression function it has to compile the expression and then apply that compiled expression to the string. Where the str_replace is directly manipulating the string which is quicker than preg_replace's method. The only time the overhead is acceptable would be when you're string is not entirely known, so: preg_replace('foo-bar-', '', $str); Can simply be changed to: str_replace('foo-bar-', '', $str); The expression, however: preg_replace('foo-\w+-', '', $str); Can't be done with str_replace. As for the resouce usage vs. ereg and preg, I believe it is entirely the nature of the libraries that they use. I don't think the source of the functions will reveal too much. just a few of my thoughts on this subject. Thanks for your time. Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php