Home > Backend Development > PHP Tutorial > 数字转换问题

数字转换问题

WBOY
Release: 2016-06-23 13:27:30
Original
792 people have browsed it

一个变量值为“20150829”,如何转化成“2015年08月29日”?谢谢


回复讨论(解决方案)

<?phpheader('Content-type:text/html;charset=utf-8');$str = '20150829';function str_to_date($str){	$str1 = substr($str, 0, 4);	$str2 = substr($str, 4, 2);	$str3 = substr($str, 6, 2);	$date = $str1 . '年' . $str2 . '月' . $str3 . '日';	return $date;  }echo str_to_date($str);
Copy after login

$s = '20150829';echo preg_replace('/(\d{4})(\d{2})(\d{2})/', '$1年$2月$3日', $s);//或echo date('Y年m月d日', strtotime($s));
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template