本文整理汇总了PHP中FabrikWorker::stripDay方法的典型用法代码示例。如果您正苦于以下问题:PHP FabrikWorker::stripDay方法的具体用法?PHP FabrikWorker::stripDay怎么用?PHP FabrikWorker::stripDay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FabrikWorker
的用法示例。
在下文中一共展示了FabrikWorker::stripDay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: str2Time
/**
*
* @param string date representation
* @param string format that the date should be in
* @return array date bits keyed on date representations e.g. m/d/Y
*/
function str2Time($date, $format)
{
static $finalformat;
/**
* 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();
preg_match("/now/i", $date, $matches);
//eg now
preg_match("/[+|-][0-9]* (week\\b|year\\b|day\\b|month\\b)/i", $date, $matches2);
//eg +2 Week
preg_match("/[next|last]* (\\monday\\b|tuesday\\b|wednesday\\b|thursday\\b|friday\\b|saturday\\b|sunday\\b)/i", $date, $matches3);
//eg next wednesday
$matches = array_merge($matches, $matches, $matches2);
if (!empty($matches)) {
$d = JFactory::getDate($date);
//$date = $d->toMySQL();
//$$$rob set to $format as we expect $date to already be in $format
$date = $d->toFormat($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 = FabrikWorker::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 = FabrikWorker::monthToInt($date, $month == '%B' ? false : true);
}
}
//@TODO: some of these arent right for strftime
$this->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 - eg 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));
$this->finalformat = $format;
return FabrikWorker::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;
}