本文整理汇总了PHP中CDateTimeParser::_mbstringAvailable方法的典型用法代码示例。如果您正苦于以下问题:PHP CDateTimeParser::_mbstringAvailable方法的具体用法?PHP CDateTimeParser::_mbstringAvailable怎么用?PHP CDateTimeParser::_mbstringAvailable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDateTimeParser
的用法示例。
在下文中一共展示了CDateTimeParser::_mbstringAvailable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Converts a date string to a timestamp.
* @param string $value the date string to be parsed
* @param string $pattern the pattern that the date string is following
* @param array $defaults the default values for year, month, day, hour, minute and second.
* The default values will be used in case when the pattern doesn't specify the
* corresponding fields. For example, if the pattern is 'MM/dd/yyyy' and this
* parameter is array('minute'=>0, 'second'=>0), then the actual minute and second
* for the parsing result will take value 0, while the actual hour value will be
* the current hour obtained by date('H'). This parameter has been available since version 1.1.5.
* @return integer timestamp for the date string. False if parsing fails.
*/
public static function parse($value, $pattern = 'MM/dd/yyyy', $defaults = array())
{
if (self::$_mbstringAvailable === null) {
self::$_mbstringAvailable = extension_loaded('mbstring');
}
$tokens = self::tokenize($pattern);
$i = 0;
$n = self::$_mbstringAvailable ? mb_strlen($value, Yii::app()->charset) : strlen($value);
foreach ($tokens as $token) {
switch ($token) {
case 'yyyy':
case 'y':
if (($year = self::parseInteger($value, $i, 4, 4)) === false) {
return false;
}
$i += 4;
break;
case 'yy':
if (($year = self::parseInteger($value, $i, 1, 2)) === false) {
return false;
}
$i += strlen($year);
break;
case 'MMMM':
$monthName = '';
if (($month = self::parseMonth($value, $i, 'wide', $monthName)) === false) {
return false;
}
$i += self::$_mbstringAvailable ? mb_strlen($monthName, Yii::app()->charset) : strlen($monthName);
break;
case 'MMM':
$monthName = '';
if (($month = self::parseMonth($value, $i, 'abbreviated', $monthName)) === false) {
return false;
}
$i += self::$_mbstringAvailable ? mb_strlen($monthName, Yii::app()->charset) : strlen($monthName);
break;
case 'MM':
if (($month = self::parseInteger($value, $i, 2, 2)) === false) {
return false;
}
$i += 2;
break;
case 'M':
if (($month = self::parseInteger($value, $i, 1, 2)) === false) {
return false;
}
$i += strlen($month);
break;
case 'dd':
if (($day = self::parseInteger($value, $i, 2, 2)) === false) {
return false;
}
$i += 2;
break;
case 'd':
if (($day = self::parseInteger($value, $i, 1, 2)) === false) {
return false;
}
$i += strlen($day);
break;
case 'h':
case 'H':
if (($hour = self::parseInteger($value, $i, 1, 2)) === false) {
return false;
}
$i += strlen($hour);
break;
case 'hh':
case 'HH':
if (($hour = self::parseInteger($value, $i, 2, 2)) === false) {
return false;
}
$i += 2;
break;
case 'm':
if (($minute = self::parseInteger($value, $i, 1, 2)) === false) {
return false;
}
$i += strlen($minute);
break;
case 'mm':
if (($minute = self::parseInteger($value, $i, 2, 2)) === false) {
return false;
}
$i += 2;
break;
case 's':
//.........这里部分代码省略.........