本文整理汇总了PHP中FabrikWorker::finalformat方法的典型用法代码示例。如果您正苦于以下问题:PHP FabrikWorker::finalformat方法的具体用法?PHP FabrikWorker::finalformat怎么用?PHP FabrikWorker::finalformat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FabrikWorker
的用法示例。
在下文中一共展示了FabrikWorker::finalformat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: str2Time
/**
* String to time
*
* @param string $date Date representation
* @param string $format Date format
*
* @return array date bits keyed on date representations e.g. m/d/Y
*/
public static function str2Time($date, $format)
{
/**
* lets check if we have some special text as per :
* http://php.net/strtotime - this means we can use "+2 week" as a url filter
* do this before we urldecode the date otherwise the + is replaced with ' ';
*/
$matches = array();
$matches2 = array();
$matches3 = array();
// E.g. now
preg_match("/[now|ago|midnight|yesterday|today]/i", $date, $matches);
// E.g. +2 Week
preg_match("/[+|-][0-9]* (week\\b|year\\b|day\\b|month\\b)/i", $date, $matches2);
// E.g. next Wednesday
preg_match("/[next|last]* (\\monday\\b|tuesday\\b|wednesday\\b|thursday\\b|friday\\b|saturday\\b|sunday\\b)/i", $date, $matches3);
$matches = array_merge($matches, $matches2, $matches3);
if (!empty($matches)) {
$d = JFactory::getDate($date);
$date = $d->format($format);
}
/* $$$ - hugh : urldecode (useful when ajax calls, may need better fix)
* as per http://fabrikar.com/forums/showthread.php?p=43314#post43314
*/
$date = urldecode($date);
// Strip any textual date representations from the string
$days = array('%A', '%a');
foreach ($days as $day) {
if (strstr($format, $day)) {
$format = str_replace($day, '', $format);
$date = self::stripDay($date, $day == '%a' ? true : false);
}
}
$months = array('%B', '%b', '%h');
foreach ($months as $month) {
if (strstr($format, $month)) {
$format = str_replace($month, '%m', $format);
$date = self::monthToInt($date, $month == '%B' ? false : true);
}
}
// @TODO: some of these aren't right for strftime
self::$finalformat = $format;
$search = array('%d', '%e', '%D', '%j', '%m', '%b', '%Y', '%y', '%g', '%H', '%h', '%i', '%s', '%S', '%M');
$replace = array('(\\d{2})', '(\\d{1,2})', '(\\w{3})', '(\\d{1,2})', '(\\d{2})', '(\\w{3})', '(\\d{4})', '(\\d{2})', '(\\d{1,2})', '(\\d{2})', '(\\d{2})', '(\\d{2})', '(\\d{2})', '(\\d{2})', '(\\d{2})');
$pattern = str_replace($search, $replace, $format);
if (!preg_match("#{$pattern}#", $date, $matches)) {
// Lets allow for partial date formats - e.g. just the date and ignore the time
$format = explode('%', $format);
if (empty($format)) {
// No format left to test so return false
return false;
}
array_pop($format);
$format = trim(implode('%', $format));
self::$finalformat = $format;
return self::str2Time($date, $format);
}
$dp = $matches;
if (!preg_match_all('#%(\\w)#', $format, $matches)) {
return false;
}
$id = $matches['1'];
if (count($dp) != count($id) + 1) {
return false;
}
$ret = array();
for ($i = 0, $j = count($id); $i < $j; $i++) {
$ret[$id[$i]] = $dp[$i + 1];
}
return $ret;
}