Search code examples
phpphp-5.3

Warning: preg_match() [function.preg-match]: Unknown modifier '-'


I change ereg to preg_match for update mycode to PHP5.3 . now i see this warning in my page. how to fix this ?

warning :

Warning: preg_match() [function.preg-match]: Unknown modifier '-' in C:\xampp\htdocs\share\configs\functions.php on line 2645

old Code :

if (!ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $dateOfBirth, $regs))

New Code (PHP 5.3):

if (!preg_match ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $dateOfBirth, $regs))

Thanks


Solution

  • You need to add delimiters:

    if (!preg_match ("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/", $dateOfBirth, $regs))
    #                 ^                                    ^