You use /
as delimiter for your expression. However, it's completely unnecessary anyway
$parts = explode('/', $date);
Even better: http://php.net/datetime.createfromformat
To give you an idea what happens: PCRE regular expression require a delimiter at the start and the end of the pattern itself. Everything after the second delimiter is treated as modifier. Thus you decided to use /
as delimiter (it's always the first character), so your pattern ended right after /^([0-9]{2})/
. Everything next (which is a (
at first) is treated as modifier, but (
is not an existing modifier.
If you want to stay with regular expression, I recommend to use another delimiter like
~^([0-9]{2})/([0-9]{2})/([0-9]{4})$~
#^([0-9]{2})/([0-9]{2})/([0-9]{4})$#
Just read the manual about the PCRE-extension
Two additional comments:
- You should define
$parts
, before you use it
- Remember, that the expression is quite inaccurate, because it allows dates like
33/44/5678
, but denies 1/1/1970