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'会是你的正则表达式的简化版本。我不确定你甚至需要为此使用正则表达式;至少不是你的程度。 –