當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CDateTimeParser::_mbstringAvailable方法代碼示例

本文整理匯總了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':
//.........這裏部分代碼省略.........
開發者ID:karikeb,項目名稱:final2015,代碼行數:101,代碼來源:CDateTimeParser.php


注:本文中的CDateTimeParser::_mbstringAvailable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。