如何将 laravel 4.2 中的工作日转换为小时?

How to convert week-days into hours in laravel 4.2?

1-如果任何用户在输入字段中输入 1w2d。

2-此输入字段中的值应转换为总小时数。

3之后我必须将这些总小时数插入数据库。

4当我从数据库中获取总小时数时,它应该 return 1w2d.

可能的表示法是有一个名为 Estimated time 的输入字段,用户可以在其中输入 1w2d 或 1W2D。这应该转换为总数 hours.After,我必须将其发送到数据库中。

*我感觉 helpless.I 不知道要 do.I 知道如何转换周 转换为小时,但不知道如何将 1w2d 转换为小时。

<?php

function convertWDHtoHours($data) {

  preg_match_all('/(\d+[wW]+|\d+[dD]+|\d+[hH]+)/', $data, $matches);
  $hours = 0;
  foreach($matches[0] AS $match) {
    switch(true) {
      case preg_match('/\d+[hH]+/', $match) :
        $hours += (int)$match;
        break;

      case preg_match('/\d+[dD]+/', $match) :
        $hours += (int)$match*24;
        break;

      case preg_match('/\d+[wW]+/', $match) :
        $hours += (int)$match*24*7;
        break;
    }
  }
  return $hours;
}

print "23h => ".convertWDHtoHours('23h')."<br/>";
print "20d => ".convertWDHtoHours('20d')."<br/>";
print "2W => ".convertWDHtoHours('2W')."<br/>";
print "1D2h => ".convertWDHtoHours('1D2h')."<br/>";
print "1w2H => ".convertWDHtoHours('1w2H')."<br/>";
print "1w2d => ".convertWDHtoHours('1w2d')."<br/>";

?>

这是结果:

http://codepad.viper-7.com/Ioj02x