What I'm trying to do here is to get the hours and minutes off of a string such as
All of the above can be entered by the user and I've come up with a regex I think works to do this job. (All of the above can be read as 2 hours and 50 minutes by a human right? (Except for the bottom two which are 2 hours.) And I'm sure this regex works since I've tested it with ereg.)
$regex = "^([0-9]?[0-9])(:|\.| )?([0-9][0-9])?$"; if ( preg_match( $regex, $_POST['user_field_goes_here'], $matches ) ) die( "Ok...it works." ); else die( "Nope. Still no good result. =(" );
But when I try to get the groups into $matches array the function returns false?!?!?! Heck it does so even without the $matches array as an argument.
The problem is I always get the sad smiley, ok! =S Is there something weird about this function or what?
I mean. Try running this:
$regex = "^([0-9]?[0-9])(:|\.| )?([0-9][0-9])?$"; if ( ereg( $regex, $_POST['user_field_goes_here'] ) ) die( "Jay." ); else die( "No." );
Tell me what?! Ahh, you got the "Jay." eh? =) It's weird.