How do you write a regular expression like this?
Mon-fri 8:00-23:00; Sat 10:00-23:00; Sun 10:00am-10:00pm;
Turn the above into Monday ~ Friday 8:00-23:00; Saturday 10:00-23:00; Sunday-10:00am;
$str = "Mon-fri 8:00-23:00; Sat 10:00-23:00; Sun 10:00am; "
$en =array ("Mon", "Fri", "Sat", "Sun");
$CN =array ("Monday", "Friday", "Saturday", "Sunday");
$str =str_replace ($en, $CN, $STR);
How to turn the English "-" into a ~, time between the non-replacement?
How to replace the space between English and digital?
Share to:
------Solution--------------------
$str = "Mon-fri 8:00-23:00; Sat 10:00-23:00; Sun 10:00am-10:00pm ";
$en =array ("Mon", "Fri", "Sat", "Sun");
$CN =array ("Monday", "Friday", "Saturday", "Sunday");
$str =str_replace ($en, $CN, $STR);
Echo $str;
$a [0]= '/([^\d]+) \-/';
$a [1]= '/\s (\d)/';
$b [0]= ' \1~ ';
$b [1]= ' \1 ';
$str =preg_replace ($a, $b, $str);
Echo $str;