: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Cached PCRE for SimplePie_Parse_Date::$day
* Cached PCRE for SimplePie_Parse_Date::$month
* Array of user-added callback methods
* Array of user-added callback methods
* Create new SimplePie_Parse_Date object, and set self::day_pcre,
* self::month_pcre, and self::built_in
public function __construct()
$this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')';
$this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')';
if (!isset($cache[get_class($this)]))
$all_methods = get_class_methods($this);
foreach ($all_methods as $method)
if (strtolower(substr($method, 0, 5)) === 'date_')
$cache[get_class($this)][] = $method;
foreach ($cache[get_class($this)] as $method)
$this->built_in[] = $method;
public static function get()
$object = new SimplePie_Parse_Date;
* @param string $date Date to parse
* @return int Timestamp corresponding to date string, or false on failure
public function parse($date)
foreach ($this->user as $method)
if (($returned = call_user_func($method, $date)) !== false)
foreach ($this->built_in as $method)
if (($returned = call_user_func(array($this, $method), $date)) !== false)
* Add a callback method to parse a date
* @param callback $callback
public function add_callback($callback)
if (is_callable($callback))
$this->user[] = $callback;
trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
* Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
* well as allowing any of upper or lower case "T", horizontal tabs, or
* spaces to be used as the time separator (including more than one))
public function date_w3cdtf($date)
$month = $day = $hour = $minute = $second = '([0-9]{2})';
$zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
$pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
if (preg_match($pcre, $date, $match))
7: Decimal fraction of a second
for ($i = count($match); $i <= 3; $i++)
for ($i = count($match); $i <= 7; $i++)
if (isset($match[9]) && $match[9] !== '')
$timezone = $match[10] * 3600;
$timezone += $match[11] * 60;
$timezone = 0 - $timezone;
// Convert the number of seconds to an integer, taking decimals into account
$second = round((int)$match[6] + (int)$match[7] / (10 ** strlen($match[7])));
return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
* @param string $data Data to strip comments from
* @return string Comment stripped string
public function remove_rfc2822_comments($string)
$string = (string) $string;
$length = strlen($string);
while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
$output .= substr($string, $position, $pos - $position);
if ($pos === 0 || $string[$pos - 1] !== '\\')
while ($depth && $position < $length)
$position += strcspn($string, '()', $position);
if ($string[$position - 1] === '\\')
elseif (isset($string[$position]))
switch ($string[$position])
$output .= substr($string, $position);
* Parse RFC2822's date format
public function date_rfc2822($date)
$fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
$optional_fws = $fws . '?';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$hour = $minute = $second = '([0-9]{2})';
$num_zone = '([+\-])([0-9]{2})([0-9]{2})';
$character_zone = '([A-Z]{1,5})';
$zone = '(?:' . $num_zone . '|' . $character_zone . ')';
$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';
if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
$month = $this->month[strtolower($match[3])];
$timezone = $match[9] * 3600;
$timezone += $match[10] * 60;
$timezone = 0 - $timezone;
elseif (isset($this->timezone[strtoupper($match[11])]))
$timezone = $this->timezone[strtoupper($match[11])];
// Assume everything else to be -0000
// Deal with 2/3 digit years
elseif ($match[4] < 1000)
// Second is optional, if it is empty set it to zero
return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
* Parse RFC850's date format
public function date_rfc850($date)
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$year = $hour = $minute = $second = '([0-9]{2})';
$pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
if (preg_match($pcre, $date, $match))
$month = $this->month[strtolower($match[3])];
if (isset($this->timezone[strtoupper($match[8])]))
$timezone = $this->timezone[strtoupper($match[8])];
// Assume everything else to be -0000
// Deal with 2 digit year
return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
* Parse C99's asctime()'s date format
public function date_asctime($date)
$wday_name = $this->day_pcre;
$mon_name = $this->month_pcre;
$hour = $sec = $min = '([0-9]{2})';
$terminator = '\x0A?\x00?';
$pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
if (preg_match($pcre, $date, $match))