2011-07-19 32 views
1

我有一个开源的程序,我正在尝试集成到一个网站中。我想更新一个代码,导致我的开发LAMP设置出现问题。弃用的eregi调用,preg_match修复需要

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(由于事先)

回答

2

您需要包装用非字母数字的和非反斜线字符(同每边一个)一个预浸料的表达。

所以,与其这样:

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) 
+0

谢谢你一个非常快速的响应,欢呼声...... –