- 论坛徽章:
- 0
|
18题- <?php
- //18、请使用一句话将类似“1910-09-09”的日期各式转换为“一九一零年九月九日”这样的各式。(需要有通用性,是不是一句话不是关键,但不允许使用if\switch\while\for等语句)。
- function date2Chinese($date) {
- //TODO check date format
- $replaces = array('0'=>'零','1'=>'一','2'=>'二','3'=>'三','4'=>'四','5'=>'五','6'=>'六','7'=>'七','8'=>'八','9'=>'九');
- $adate = explode('-', $date);
- return strtr((int)$adate[0], $replaces) . '年' . strtr((int)$adate[1], $replaces) . '月' . strtr((int)$adate[2], $replaces) . '日';
- }
- $str = file_get_contents('in.txt');
- //$str = '1901-01-01';
- echo date2Chinese($str);
复制代码 |
|