Home >Backend Development >PHP Tutorial > 一个截取有关问题

一个截取有关问题

WBOY
WBOYOriginal
2016-06-13 13:18:55762browse

一个截取问题?
2012-01-02 00:00:01

我想最后截取的是‘201201’

我应该怎么做

------解决方案--------------------

PHP code
"echo date('Ym', time());"
<br><font color="#e78608">------解决方案--------------------</font><br>
PHP code

function get_cut($str, $num = 6){
    $str = str_replace('-', '', $str);
    preg_match('/\d{' . $num . '}/', $str, $arr);
    return $arr[0];
}
echo get_cut('2012-03-14'); // 201203
echo get_cut('2012-03-14', 8); // 20120314
<br><font color="#e78608">------解决方案--------------------</font><br>$s='2012-03-14';<br>echo date("Ym",strtotime($s)); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn