Do I need to be a regular expression? If not:
$daysStart = 'Mon,Tues,Wed,mon'; $days = strtolower($daysStart); $days = explode(",", $days); // split on comma $days = array_unique($days); // remove uniques $days = implode(",", $days); // join on comma // Compare new string to original: if(strtolower($days)===strtolower($daysStart )){ /*match*/ }
The result is a string of days, separated by commas. Not sure what you want as output, you might want to save the original input in other distant or ucfirst() values ββwith array_map() or something else, this will just show you a different method
Or my code is shorter:
$daysStart = 'Mon,Tues,Wed,mon'; $days = explode(",", strtolower($daysStart ) ); $days = implode(",", array_unique($days) ); if(strtolower($days)===strtolower($daysStart )){ }
or function (like a short code, maybe a longer version):
function checkDays($string){ $days = explode(",", strtolower($string) ); $days = implode(",", array_unique($days) ); return (strtolower($days)===strtolower($daysStart)) ? true : false;
* I could only do the return and str checks, but I prefer to add true / false so that I am sure that the return value is always true for false as logical, and not true or false.
Martijn
source share