2
- 用戶在輸入字段中輸入了
2w2d2h
。 - 在數據庫中顯示
386
。 2w=2*24*7
2d-2*24
2h=2
- 加入上述三個值後,它變得
386
。 - 現在來自數據庫,當我將取
386
它應該顯示2w2d2h
。
截至轉換後,我現在已經插入值。
preg_match_all('#(\d[wW]+|\d[dD]+|\d[hH]+|\s+)#i', $category, $matches);
$hours = 0;
$days = 0;
$hoursss = 0;
foreach ($matches[0] AS $match) {
switch(true) {
case preg_match('/\d[hH]+|\s+/', $match):
$hours += (int)$match;
break;
case preg_match('/\d[dD]+|\s+/', $match):
$days += (int)$match * 24;
break;
case preg_match('/\d[wW]+|s+/', $match):
$hoursss += (int)$match * 24 * 7;
break;
}
$case = $hours + $hoursss + $days;
}
我注意到相信你已做了你的問題清楚。你真的需要什麼幫助? – RiggsFolly
'/ \ d + [wdh]/i'會是你的正則表達式的簡化版本。我不確定你甚至需要爲此使用正則表達式;至少不是你的程度。 –