回答編集履歴
1
追記
answer
CHANGED
@@ -13,4 +13,22 @@
|
|
13
13
|
}
|
14
14
|
}
|
15
15
|
|
16
|
+
```
|
17
|
+
# 追記
|
18
|
+
例えばこうすると年月だけ拾えます
|
19
|
+
```PHP
|
20
|
+
print normalizeTime("2017年2月16日")."<br>";// y/m/d
|
21
|
+
print normalizeTime("2017年2月")."<br>";// y/m
|
22
|
+
print normalizeTime("2017年2月99日")."<br>";// ありえない日付なので不明
|
23
|
+
print normalizeTime("2017年2月160日")."<br>"; // 日付が3桁なので日付を無視して y/m
|
24
|
+
|
25
|
+
function normalizeTime($date_str) {
|
26
|
+
$pattern="/(\d{4})年(\d{1,2})月(?:(\d{1,2})(?=日))?/";
|
27
|
+
if(preg_match($pattern,$date_str,$match) and checkdate($match[2],isset($match[3])?$match[3]:1,$match[1])){
|
28
|
+
return date(isset($match[3])?"Y/m/d":"Y/m",mktime(0,0,0,$match[2],isset($match[3])?$match[3]:1,$match[1]));
|
29
|
+
}else{
|
30
|
+
return "不明";
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
16
34
|
```
|