Automatically exported from code.google.com/p/planningalerts
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

shared.make_timestamp.php 1.1 KiB

hace 18 años
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. ?>