Automatically exported from code.google.com/p/planningalerts
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

shared.make_timestamp.php 1.1 KiB

il y a 17 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. ?>