Jump to content

Deprecated: Function eregi() Please Help.. Been working on this for a while


defecto

Recommended Posts

Im new to php and Im working on a script that I purchased.  I'm getting this error when I try to setup my script. I did some research and understand that I "eregi" is old code and not being used anymore. So I tried to use preg_match but I'm stuck. If anyone can look at the code and help with some notes. I would like to understand what im doing wrong not just a fix.

 

Deprecated: Function eregi()

 if (eregi($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file;

 

This is what I get when using preg_match.

 

preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash

if (preg_match($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file; 

 

Try this:

 

if (preg_match("|$file|i",$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file;

 

The preg functions need a delimiter around the expression being searched for.  That's because it came from perl, which expects delimiters.  I've used "|" as the delimiter here.  And the "i" at the end means "case insensitive".

The short answer is it doesn't matter, but it's helpful to choose your delimiter so it doesn't conflict with the regexp.  In your case you are looking for a file, so I used pipe instead of slash, as there's a chance $file will have slashes in it.  It's very unlikely for it to have a pipe though.

 

You can still use the delimiter but you'll need to escape it.  The following are equivalent:

 

'/foo\/bar.txt/'
'|foo/bar.txt|'

 

So by choosing pipe as delimiter, there's no need to escape the slash.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.