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

和自甴很熟 提交于 2019-11-28 11:15:15

问题


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


回答1:


You need to add delimiters:

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


来源:https://stackoverflow.com/questions/11665632/warning-preg-match-function-preg-match-unknown-modifier

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!