3
A
回答
4
您可以使用PHP字符串函数substr
为:
$year = substr($date,0,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.
如果您的原始字符串作为前导空格或尾随空格将会失败,所以其更好的输入为substr
。你叫那么之前substr
,你可以这样做:
$date = trim($date);
1
您可以使用字符串函数
http://www.w3schools.com/php/func_string_substr.asp
$year=substr($date,0,4);
$month=substr($date,4,2);
$day=substr($date,6,2);
2
您可以
sscanf
做这一切一气呵成 - 根据格式 解析来自字符串的输入
例子:
list($y, $m, $d) = sscanf('20101015', '%4d%2d%2d');
或
sscanf('20101015', '%4d%2d%2d', $y, $m, $d);
相关问题
- 1. 分裂,月份和年份变量
- 2. daterangepicker难以查看月份和年份
- 3. 按年份和月份
- 4. 只月份和年份
- 5. SQL:按月份和年份
- 6. 从月到年和月份
- 7. 匹配月份和年份Python和datetime
- 8. 选择开始年份和开始月份之间的数据以结束年份和结束月份?
- 9. 月份及年份过滤
- 10. T-SQL:从月份列中合并当前年份和月份
- 11. 如何将月份转换为java中的年份和月份
- 12. 如何从年份和月份中扣除月份
- 13. 使用jquery验证月份和年份
- 14. CriteriaQuery月份和年份筛选器
- 15. 参考月份和年份PostgreSQL中
- 16. 按月份和年份分组
- 17. 红宝石组按月份和年份
- 18. Mysql月份和年份的数据
- 19. UIDatePicker选择月份和年份
- 20. 如何按年份和月份分组?
- 21. 查找月份和年份内串
- 22. 获取特定年份和月份
- 23. 子集为指定月份和年份
- 24. 按月份和年份分组
- 25. Rails:按月份和年份查询ActiveRecord
- 26. Mysql - 获取月份和年份#
- 27. 创建的年份和月份
- 28. 在android中获取月份和年份?
- 29. 熊猫GROUPBY月份和年份
- 30. 从SQL获取年份和月份
http://php.net/manual/en/function.substr.php - 严重的是,这是一个懒惰的问题。 – Tomalak 2010-10-14 06:34:45
你的意思是$天= 15? – Gunjan 2010-10-14 06:35:27