跳转到内容


php正则匹配获得年月日方法


  • 您无法回复此主题
No replies to this topic

#1 iceqi

    新手上路

  • 注册用户
  • 点子
  • 9 帖子数:

发表于 2012/02/12 16:57:04

今天掌握了一个小技巧,用正则匹配获得年月日

<?php
$date_str = '1987-08-28';
if(preg_match('/^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})$/', $date_str, $matchs))
{
    echo $matchs[1] . "年" . $matchs[2] . "月" . $matchs[3] . "日";
}
else
{
    echo '日期格式不正确';
}






目前查看此主题的用户: 1 位

0 位会员, 1 位游客, 0 位隐身会员