Automatically exported from code.google.com/p/planningalerts
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

47 行
1.1 KiB

  1. <?php
  2. /**
  3. * Smarty shared plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Function: smarty_make_timestamp<br>
  9. * Purpose: used by other smarty functions to make a timestamp
  10. * from a string.
  11. * @author Monte Ohrt <monte at ohrt dot com>
  12. * @param string
  13. * @return string
  14. */
  15. function smarty_make_timestamp($string)
  16. {
  17. if(empty($string)) {
  18. // use "now":
  19. $time = time();
  20. } elseif (preg_match('/^\d{14}$/', $string)) {
  21. // it is mysql timestamp format of YYYYMMDDHHMMSS?
  22. $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
  23. substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));
  24. } elseif (is_numeric($string)) {
  25. // it is a numeric string, we handle it as timestamp
  26. $time = (int)$string;
  27. } else {
  28. // strtotime should handle it
  29. $time = strtotime($string);
  30. if ($time == -1 || $time === false) {
  31. // strtotime() was not able to parse $string, use "now":
  32. $time = time();
  33. }
  34. }
  35. return $time;
  36. }
  37. /* vim: set expandtab: */
  38. ?>