$str = "2008年09月15日";
$str = preg_replace('/([\d]{4})[^\d]+([\d]{2})[^\d]+([\d]{2})[^\d]+/',"$1-$2-$3",$str);

解决方案 »

  1.   


    $str='2008年9月15日';
    $replace_data = preg_replace('/[^\d]+/','-',$str);
    $replace_data = trim($replace_data,'-');
    echo date('Y-m-d',strtotime($replace_data));
      

  2.   

    fix一下二楼的正则,$str = "2008年09月15日"; 
    $str2 = "2008年9月15日"; 
    $str = preg_replace('/([\d]{4})[^\d]+([\d]{1,2})[^\d]+([\d]{2})[^\d]+/',"$1-$2-$3",$str); 
    $str2 = preg_replace('/([\d]{4})[^\d]+([\d]{1,2})[^\d]+([\d]{2})[^\d]+/',"$1-$2-$3",$str2); 
      

  3.   

    呵呵.ms也有可能有这种情况吧. 2008年9月5日
    没太注意需求
    $str = "2008年09月15日"; 
    $str = preg_replace('/([\d]{4})[^\d]+([\d]{1,2})[^\d]+([\d]{1,2})[^\d]+/',"$1-$2-$3",$str);