y( 'hour', '\d{2}' ), 'g' => array( 'hour', '\d{1,2}' ), 'G' => array( 'hour', '\d{1,2}' ), 'i' => array( 'minute', '\d{2}' ), 's' => array( 'second', '\d{2}' ) ); // convert format string to regex $regex = ''; $chars = str_split( $format ); foreach ( $chars AS $n => $char ) { $lastChar = isset( $chars[$n - 1] ) ? $chars[$n - 1] : ''; $skipCurrent = '\\' == $lastChar; if ( !$skipCurrent && isset( $keys[$char] ) ) { $regex .= '(?P<' . $keys[$char][0] . '>' . $keys[$char][1] . ')'; } else if ( '\\' == $char ) { $regex .= $char; } else { $regex .= preg_quote( $char ); } } $dt = array(); // now try to match it if ( preg_match( '#^' . $regex . '$#', $date, $dt ) ) { foreach ( $dt AS $k => $v ) { if ( is_int( $k ) ) { unset( $dt[$k] ); } } if ( ! checkdate( $dt['month'], $dt['day'], $dt['year'] ) ) { $dt['error_count'] = 1; } else { $dt['error_count'] = 0; } if ( ! isset( $dt['hour'] ) ) { $dt['hour'] = 0; } if ( ! isset( $dt['minute'] ) ) { $dt['minute'] = 0; } if ( ! isset( $dt['second'] ) ) { $dt['second'] = 0; } } else { $dt['error_count'] = 1; } $dt['errors'] = array(); $dt['fraction'] = ''; $dt['warning_count'] = 0; $dt['warnings'] = array(); $dt['is_localtime'] = 0; $dt['zone_type'] = 0; $dt['zone'] = 0; $dt['is_dst'] = ''; return $dt; } }