$string = "April 15, 2003";
$pattern = "/(\w+) (\d+), (\d+)/i";
$replacement = "\${1}1,\${3}";
print preg_replace($pattern, $replacement, $string);
//April1,2003
转载于:https://www.cnblogs.com/7bus/archive/2011/08/02/2124823.html
PHP日期格式转换
本文介绍了一个使用PHP进行日期格式转换的例子。通过正则表达式匹配并替换的方式,将特定格式的日期字符串转换为另一种格式。具体操作是将'April15,2003'这样的字符串转换成'April1,2003'的形式。
$string = "April 15, 2003";
$pattern = "/(\w+) (\d+), (\d+)/i";
$replacement = "\${1}1,\${3}";
print preg_replace($pattern, $replacement, $string);
//April1,2003
转载于:https://www.cnblogs.com/7bus/archive/2011/08/02/2124823.html

被折叠的 条评论
为什么被折叠?