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; 

 

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.