Since you are replacing one character with another character, a regex based solution is an overkill. You can just use str_replace
as:
$edited_date = str_replace(array('/','-'),'',$date);
Now what was wrong with your preg_replace
?
preg_replace
expects the regex to be surrounded by a pair of delimiters. So this should have worked:
$edited_date = preg_replace('#-#','',$date);
Also as str_replace
, preg_replace
also accepts arrays, so you can do:
$from = array('#/#','#-#');
$to = '';
$edited_date = preg_replace($from,$to,$date);
Also you can combine the two patterns to be removed in a single regex as:
$edited_date = preg_replace('#-|/#','',$date);