I had this original code:
/**
* IP address conversion: A.B.C.D -> log
*
* @param string $string IP Address: A.B.C.D
* @return long
* @access private
* @static
* @since 1.0
*/
private function convert2number($string)
{
$pattern= "\"([0-9]+)\"";
if (ereg($pattern, $string, $regs))
return (int)$regs[1];
}
/**
* IP conversion
*
* @param string $address IP address in the A.B.C.D format
* @return long
* @access private
* @static
* @since 1.0
*/
private function IpAddress2IpNumber($address)
{
$pattern = "([0-9]+).([0-9]+).([0-9]+).([0-9]+)";
if (ereg($pattern, $address, $regs))
return $number = $regs[1] * 256 * 256 * 256 + $regs[2] * 256 * 256 + $regs[3] * 256 + $regs[4];
else
return false;
}
Since PHP 5.3, ereg
was Deprecated, I researched this, and I stumbled upon a suggestion to replace ereg
with preg_match
, I did so, and I got a new error:
Warning: preg_match(): Unknown modifier '.' in geoip.php on line 222
Code:
/**
* IP conversion
*
* @param string $address IP address in the A.B.C.D format
* @return long
* @access private
* @static
* @since 1.0
*/
private function IpAddress2IpNumber($address)
{
$pattern = "([0-9]+).([0-9]+).([0-9]+).([0-9]+)";
if (preg_match($pattern, $address, $regs))
return $number = $regs[1] * 256 * 256 * 256 + $regs[2] * 256 * 256 + $regs[3] * 256 + $regs[4];
else
return false;
}
How do I go about fixing this? Any recommendation? Thanks!