With a post request, I'm trying to return a booking number to my iOS App. It posts the current date as a string which is written to a file on my server.
The logic is, that whenever the date from the last entry does not match the date passed in the post request, the booking number starts from 01. If it is the same date, the booking number gets increased by one.
The text file I write my entries to looks like this:
2017-03-03, 1;
2017-03-03, 2;
2017-03-03, 3;
2017-03-03, 4;
2017-03-03, 5
I am using regex to find the last entry, comparing its date to the current and assigning the new booking number. Here is my code:
if (preg_match_all("/\d{4}-\d{1,2}-\d{1,2},\s\d\z/", $textFileString, $entryArray)) {
if (preg_match_all("/\d{4}-\d{1,2}-\d{1,2}/", $entryArray[0][0], $dateArray)) {
if ($dateArray[0][0] == $currentDate) { //$currentDate's value comes from the post request
if (preg_match_all("/\d\z/", $entry[0][0], $numberArray)) {
$bookingNumber = $output_array[0][0]+1;
}
} else {
$bookingNumber = 1;
}
}
}
Note: I do successfully write to the file.
preg_match_all? Usepreg_match. Also,\zmatches the very end of string, what if there is a trailing newline? Change into$.$bookingNumberbefore these regex statements$currentDatevalue here?2017-03-02?