1

我有一个正在尝试集成到网站中的开源程序。我想更新其中导致我的开发 LAMP 设置出现问题的代码。

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'");
            }

        }

我知道不推荐使用eregi调用并且应该使用preg_match,但是它给了我以下错误...

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

如果有人可以修复它并解释为什么我将不胜感激。

TIA(提前致谢)

4

1 回答 1

3

您需要使用非字母数字和非反斜杠字符(每侧相同)包装 preg 表达式。

所以,而不是这个:

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

这个

// 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)
于 2011-07-19T03:45:53.793 回答