php var到年和月
发布时间:2020-12-13 21:38:57 所属栏目:PHP教程 来源:网络整理
导读:$date ='20101015'; 如何转换为$year = 2010,$month = 10,$day = 15 谢谢 解决方法 您可以使用PHP子字符串函数 substr : $year = substr($date,4); # extract 4 char starting at position 0.$month = substr($date,4,2); # extract 2 char starting at pos
$date ='20101015'; 如何转换为$year = 2010,$month = 10,$day = 15 谢谢 解决方法
您可以使用PHP子字符串函数
substr :
$year = substr($date,4); # extract 4 char starting at position 0. $month = substr($date,4,2); # extract 2 char starting at position 4. $day = substr($date,6); # extract all char starting at position 6 till end. 如果您的原始字符串作为前导或尾随空格,则会失败,因此其更好的Feed substr trimmed输入为.所以在你调用substr之前你可以这样做: $date = trim($date); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |