I am trying to get a return value for the day that is matched by the preg_match() function against an associative array to return the selected weekday. The code excerpt is below:
$daysArray = array(
"Monday" => "Mon",
"Tuesday" => "Tues",
"Wednesday" => "Wed",
"Thursday" => "Thurs",
"Friday" => "Fri",
"Saturday" => "Sat",
"Sunday" => "Sun"
);
$weekdaysString = implode('|',$daysArray);
if (preg_match('/^\d{1,2}.\d{2}([ap])m\[(' . $weekdaysString . '|-).Only\]$/', $val)) {
echo "Match was found <br />";
} else if (preg_match('/^\d{1,2}.\d{2}([ap])m\[(' . $weekdaysString . '|-)-(' . $weekdaysString . '|-).Only\]$/', $val)) {
echo "Match was found 3<br />";
} else {
echo 'Not found ';
}
$val is '8:55pm[Tues-Thurs Only]';
preg_match
– Havelock Apr 23 at 8:47Except
in your Pattern? Your regex doesn't match that. stackoverflow.com/questions/23221936/… – Andresch Serj Apr 23 at 8:58