how can i solve " Deprecated: Function eregi() is deprecated" error

4.3k Views Asked by At

i am using php 5.3.0 and i am use wamp server function is like that

eregi("^[ \f\r\t\n]{0,}(SELECT){1}(.+)$",$this->ss_last_query)  
eregi("^[ \f\r\t\n]{0,}(UPDATE|INSERT|DELETE){1}(.+)$",$this->ss_last_query)
3

There are 3 best solutions below

5
On

Two options

  1. Don't use the ereg* functions (use the PCRE suite instead)
  2. Disable E_DEPRECATED error reporting. See error_reporting()

The best option is #1 as the entire POSIX Extended suite will be removed in a future version.

I can't comprehend how people are still using this. It's been marked for removal for years. Not to mention the pre-deprecated "These functions are inferior!" warning that was up for even longer.

0
On

Use the preg_match with the i modifier, which specifies that you want a case insensitive match with your regex.

So you want:

preg_match("/regexhere/i", $str);

0
On
error_reporting(E_ALL ^ E_DEPRECATED);

If you must use eregi, but...

preg_match("/^[ \f\r\t\n]{0,}(UPDATE|INSERT|DELETE){1}(.+)$/is", $this->ss_last_query)

should also work.