【发布时间】:2015-10-31 18:30:19
【问题描述】:
- 用户在输入字段中输入了
2w2d2h。 - 在数据库中显示
386。 2w=2*24*72d-2*242h=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;
}
【问题讨论】:
-
我注意到您确实已经明确了您的问题。您真正需要帮助的是什么?
-
/\d+[wdh]/i将是您的正则表达式的简化版本。我不确定你甚至需要为此使用正则表达式;至少不是你现在的程度。
标签: php regex laravel laravel-4 preg-match-all