fork download
  1. <?php
  2.  
  3. date_asctime( "Mon Oct 21 11:21:31 2012\x0A" );
  4. date_asctime( "Mon Oct 22 12:22:32 2012\x0A" );
  5. date_asctime( "Mon Oct 23 13:23:33 2012\x0A" );
  6.  
  7. print("==================\n");
  8.  
  9. date_rfc2822( 'Mon, 21 Oct 2012 21:01 -1011' );
  10. date_rfc2822( 'Mon, 22 Oct 2012 22:02 -1012' );
  11. date_rfc2822( 'Mon, 23 Oct 2012 23:03 -1013' );
  12.  
  13.  
  14. /**
  15.  * Parse C99's asctime()'s date format
  16.  *
  17.  * @access protected
  18.  * @return int Timestamp
  19.  */
  20. function date_asctime($date)
  21. {
  22. static $pcre;
  23. if (!$pcre)
  24. {
  25. $space = '[\x09\x20]+';
  26.  
  27. $wday_name = 'Mon'; //$this->day_pcre;
  28. $mon_name = 'Oct'; //$this->month_pcre;
  29.  
  30. $day = '([0-9]{1,2})';
  31. $hour = $sec = $min = '([0-9]{2})';
  32. $year = '([0-9]{4})';
  33. $terminator = '\x0A?\x00?';
  34. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
  35. }
  36. if (preg_match($pcre, $date, $match))
  37. {
  38. print_r($match);
  39. }
  40. }
  41.  
  42.  
  43. /**
  44.  * Parse RFC2822's date format
  45.  *
  46.  * @access protected
  47.  * @return int Timestamp
  48.  */
  49. function date_rfc2822($date)
  50. {
  51. static $pcre;
  52. if (!$pcre)
  53. {
  54. $wsp = '[\x09\x20]';
  55.  
  56. // $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
  57. $fws = '(?:(?:(?:\x0D\x0A)?' . $wsp . ')+)';
  58. $optional_fws = $fws . '?';
  59.  
  60. $day_name = 'Mon'; //$this->day_pcre;
  61. $month = 'Oct'; //$this->month_pcre;
  62.  
  63. $day = '([0-9]{1,2})';
  64. $hour = $minute = $second = '([0-9]{2})';
  65. $year = '([0-9]{2,4})';
  66. $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
  67. $character_zone = '([A-Z]{1,5})';
  68. $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
  69. $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
  70. }
  71. // if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
  72. if (preg_match($pcre, $date, $match))
  73. {
  74. print_r($match);
  75. }
  76. }
  77. ?>
  78.  
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Mon Oct 21 11:21:31 2012

    [1] => 21
    [2] => 11
    [3] => 21
    [4] => 31
    [5] => 2012
)
Array
(
    [0] => Mon Oct 22 12:22:32 2012

    [1] => 22
    [2] => 12
    [3] => 22
    [4] => 32
    [5] => 2012
)
Array
(
    [0] => Mon Oct 23 13:23:33 2012

    [1] => 23
    [2] => 13
    [3] => 23
    [4] => 33
    [5] => 2012
)
==================
Array
(
    [0] => Mon, 21 Oct 2012 21:01 -1011
    [1] => 21
    [2] => 2012
    [3] => 21
    [4] => 01
    [5] => 
    [6] => -
    [7] => 10
    [8] => 11
)
Array
(
    [0] => Mon, 22 Oct 2012 22:02 -1012
    [1] => 22
    [2] => 2012
    [3] => 22
    [4] => 02
    [5] => 
    [6] => -
    [7] => 10
    [8] => 12
)
Array
(
    [0] => Mon, 23 Oct 2012 23:03 -1013
    [1] => 23
    [2] => 2012
    [3] => 23
    [4] => 03
    [5] => 
    [6] => -
    [7] => 10
    [8] => 13
)