Page 1 of 1
Deprecated: Function eregi_replace
Posted: Thu Nov 26, 2009 12:14 am
by lhardee
Hello all,
I'm hoping someone can assist me with an error I'm receiving. In my SQL query
I am receiving an error on the following 2 lines of code below:
Code: Select all
$TempQuery = eregi_replace("^select .* from ", "select count(0) from ", $this->Query);
$TempQuery = eregi_replace(" order by .*$", "", $TempQuery);
I believe that because I am using XAMMP, the PHP version I am using has changed and I might need to change eregi_replace to preg_replace command. However, I know nothing about this code and am hoping that someone might be able co provide the propper fix for me.
Thanks in advance,
lhardee
Re: Deprecated: Function eregi_replace
Posted: Thu Nov 26, 2009 1:00 am
by cpetercarter
http://php.net/manual/en/function.preg-replace.php
Note that with preg_replace() and other 'preg_...' functions, the regular expression needs to have a delimiter (normally /) at the beginning and the end.
Re: Deprecated: Function eregi_replace
Posted: Thu Nov 26, 2009 6:50 am
by lhardee
cpetercarter,
Thanks for your reply. I have reviewed the link you've attached and am still very confused as to what is needed in the code below.
Code: Select all
$TempQuery = preg_replace("^select (.*) from ", "select count(1) from ", $this->Query);
The error I am now receiving is:
Warning: preg_replace() [function.preg-replace]: No ending delimiter '^' found
and....
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
for the following code.
Code: Select all
$TempQuery = preg_replace(" order by .*$", "", $TempQuery);
Thanks,
lhardee
Re: Deprecated: Function eregi_replace
Posted: Thu Nov 26, 2009 10:04 am
by pickle
Try just using
str_replace() much simpler & less expensive in terms of clock cycles.
Re: Deprecated: Function eregi_replace
Posted: Fri Nov 27, 2009 4:04 am
by cpetercarter
pickle wrote:Try just using str_replace() much simpler & less expensive in terms of clock cycles.
This is good advice. Use strpos, str_replace etc where you can; keep regular expressions for the tricky stuff that only they can do.