I need to process strings that have a mostly regular format/structure. Basically, the string contains 3 keywords that always appear in the same order: ATLPáscoa
, ATLNatal
, and ATLVerão
Between these keywords are an unknown number of whitespace characters. Also, there is the possibility that each of the keywords will be followed by a date value that may consist of non-whitespace and whitespace characters.
Associated by their keyword, I want to declare 3 variables called $datePáscoa
, $dateNatal
, and $dateVerão
and assign the date substring to these variables.
Here's an example:
$string = 'ATLPáscoa ATLNatal ATLVerão Turno11-03a07desetembro';
My desired output is:
$datePáscoa = '';
$dateNatal = '';
$dateVerão = 'Turno11-03a07desetembro';
Here is another example:
$string = 'ATLPáscoa bananas ATLNatal xyza sd af ATLVerão Turno11-03a07desetembro';
My expected output is:
$datePáscoa = 'bananas';
$dateNatal = 'xyza sd af';
$dateVerão = 'Turno11-03a07desetembro';
I tried to use the str_replace()
, but it is clearly not the way:
$string = str_replace("Atelier","",$string );
$string = str_replace("Páscoa","",$string );
$string = str_replace("Natal","",$string );
$string = str_replace("Verão","",$string );
How can I extract the date values and assign the values to the appropriate variable?