开发者

Deprecated eregi Call, preg_match Fix Needed [duplicate]

This question already has answers here: How can I convert ereg expressions to preg in PHP? (4 answers) 开发者_如何学Python Closed 3 years ago.

I have an open source program I am trying to integrate in a website. I would like to update a code in it that is causing problems with my development LAMP setup.

if ($dbselect)
        {
            if (!eregi('utf',strtolower($script_encoding)) && !defined('IN_LOGINPAGE'))
            {
               mysql_query("SET NAMES 'utf8'");   
            }
               else if (empty($script_encoding) || eregi('utf',strtolower($script_encoding))) 
            {
               mysql_query("SET NAMES 'utf8'");
            }

        }

I know that eregi call is deprecated and preg_match is what should be used but it gives me a the following error...

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

if someone could fix it and explain why I would be greatly appreciated.

TIA (Thanks In Advance)


You need to wrap a preg expression with a non-alphanumeric and non-backslash character (the same one on each side).

So, instead of this:

eregi('utf',strtolower($script_encoding))

This

// wrapped in '#' (# and / are the two most common. I use # almost exclusively in PHP
// so that I don't have to escape the /)
// i = case insensitive, so you don't need strtolower
preg_match('#utf#i',$script_encoding)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜