defecto Posted March 8, 2011 Share Posted March 8, 2011 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; Quote Link to comment Share on other sites More sharing options...
btherl Posted March 8, 2011 Share Posted March 8, 2011 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". Quote Link to comment Share on other sites More sharing options...
defecto Posted March 8, 2011 Author Share Posted March 8, 2011 Does it matter what the delimiter is? Ive seen " ~ " , " / " being used. I tried the slashes but did not work. The pipe char did work.. Thank you. Quote Link to comment Share on other sites More sharing options...
salathe Posted March 8, 2011 Share Posted March 8, 2011 Have a read through of PCRE's (preg_* functions) Differences from POSIX regex (ereg* functions) page in the manual. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 9, 2011 Share Posted March 9, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.