Deprecated: Function eregi_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lhardee
Forum Newbie
Posts: 2
Joined: Thu Nov 26, 2009 12:05 am

Deprecated: Function eregi_replace

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Deprecated: Function eregi_replace

Post 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.
lhardee
Forum Newbie
Posts: 2
Joined: Thu Nov 26, 2009 12:05 am

Re: Deprecated: Function eregi_replace

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Deprecated: Function eregi_replace

Post by pickle »

Try just using str_replace() much simpler & less expensive in terms of clock cycles.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Deprecated: Function eregi_replace

Post 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.
Post Reply