I am requesting following format from user
KEYWORD <name> , <city> , <24:00 hour time>
Point 5 is most important, I want to make sure I parse <24:00 hour time> in all possible ways that I can.
What I did/want
1. Split the input to get $info (= $input - $keyword) as follows:
$key = 'abc'; $msg = 'ABC blah, blah, blah';
$pat = "/^(?i)$key/";
$split = preg_split($pat, $msg);
$info = $split[1]; //$split[0] = ''; //empty string
2. My user is dumb. S/he will be "texting (SMS)" the input. So I want to split $info
by char ,
(which hopefully will occur only twice) and store the three substrings into $usName, $usCity, $usTime
respectively (prefix us = Un-Safe data, processed data goes into DB)
So I think I will do following
$split = preg_split('/,/', $info);
foeach($split as $block) {
if(preg_match('/[12]?:\d{2}/', $block) {
$usTime = $block;
}
} //what do I do for $usName and $usCity
3. $usName
goes directly into DB (don't worry I use prepared stmts)
4. $usCity
needs to be mapped to a City in the DB table. I have indexed City_Variance and City_Key tables mapped to each other by City_Variance_City_Key table. So mistyped input can be mapped to proper indexed City name. For now assume that City_Variance has /[:upper:]+/
so no multi word cities (i.e. NOT Los Angeles
)
5. This is the most interesting part, the $usTime
. The intended use of this field is to create an appointment in nearby future. Found Datejs. This is all PHP server side code, and I don't think I can use the power of a simple JavaScript library without simulating a browser
Does anyone know a library which can help me parse user input like Datejs?