Deprecated eregi Call, preg_match Fix Needed [duplicate]
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)
精彩评论