如题:怎么将字符串2011年5月转化为日期2011-5-1???????????

解决方案 »

  1.   

    $a=array('年','月');
    $b=array('-','-1');
    echo $str=str_replace($a,$b,$str);
      

  2.   

    $s = '2011年5月';
    echo preg_replace('/\D+/', '-', $s) . '-1';
      

  3.   


    //方法一//2011年5月转化为日期2011-5-1
    $str = '';
    $s = '2011年5月';
    preg_match_all('/(\d+)/', $s, $a);
    if(isset($a[0][0])){
    $str = $a[0][0];
    if(isset($a[0][1])){
    $str .= '-' . $a[0][1];
    if(isset($a[0][2])){
    $str .= '-' . $a[0][2];
    }else{
    $str .= '-1';
    }
    }
    }
    echo $str;
      

  4.   

    echo date('Y年m月',strtotime('2011-05-01 00:00:00'));
      

  5.   


    $olddate="2011年5月"
    $olddate.="1日";
    $newdate=date("Y-n-j",$olddate);
    echo $newdate;
      

  6.   

    echo strtr('2011年5月', array('年' => '-', '月' => '-1'));