Forum Moderators: coopster

Message Too Old, No Replies

regexp faster? if so help!

regular expression ereg preg_replace str_replace

         

dougpd

4:13 pm on Nov 1, 2003 (gmt 0)

10+ Year Member



I can't figure out reg exp.

This works, but would a regexp be faster, and if so, what would it be? I'm stuck...


$kw = str_replace("0","",$kw);
$kw = str_replace("1","",$kw);
$kw = str_replace("2","",$kw);
$kw = str_replace("3","",$kw);
$kw = str_replace("4","",$kw);
$kw = str_replace("5","",$kw);
$kw = str_replace("6","",$kw);
$kw = str_replace("7","",$kw);
$kw = str_replace("8","",$kw);
$kw = str_replace("9","",$kw);
$kw = str_replace("()","",$kw);
$kw = str_replace("@","",$kw);
$kw = str_replace("(,)","",$kw);
$kw = str_replace("\n","",$kw);

killroy

4:25 pm on Nov 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should mach those char combos:

[0-9¦\n]¦\(,?\)

SN

ergophobe

6:05 pm on Nov 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




would a regexp be faster

To really find out, you need to run Apache Bench or some such thing on a small test script (many iterations) to find out. Getting the regex engin going may or may not be faster. That said,

- do you have huge bandwidth on this page?
- is this part of the script a bottleneck?

I would use the regex and then go back and optimize, especially trying to get DB queries more efficient.

Tom

dougpd

8:11 pm on Nov 2, 2003 (gmt 0)

10+ Year Member



Thanks SN and Tom,

I did end up going with a slightly modified version, but in testing of page execution times, there was o appreciable difference, so for the benefit of neater code, I used a regex. Thanks again,
dpd