1、正则去掉日期日月前面的0
<?php
$arr = [
'2019-09-03',
'2019年09月01日',
'2019/09/04',
];
$rule = '/\b0/';
foreach($arr as $str){
$newstr = preg_replace($rule, "", $str);
var_export($newstr);
}
<<<EOD
2019-9-3
2019年9月1日
2019/9/4
EOD;2、日期格式化方法(不能处理:2019年09月01日格式的)
$arr = [
'2019-09-03',
'20190901',
];
$rule = '/\b0/';
foreach($arr as $str){
$newstr = date('Y-n-j', strtotime($str));
var_export($newstr);
}
<<<EOD
2019-9-3
2019/9/4
EOD;