• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP intl_get_error_code函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中intl_get_error_code函数的典型用法代码示例。如果您正苦于以下问题:PHP intl_get_error_code函数的具体用法?PHP intl_get_error_code怎么用?PHP intl_get_error_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了intl_get_error_code函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: ut_main

function ut_main()
{
    $locale_arr = array('en_US_CA');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
    $res_str = '';
    $text_arr = array("Sunday, September 18, 3039 4:06:40 PM PT", "Thursday, December 18, 1969 8:49:59 AM PST", "12/18/69 8:49 AM", "20111218 08:49 AM", "19691218 08:49 AM");
    foreach ($text_arr as $text_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput text is : {$text_entry}";
        $res_str .= "\n------------";
        foreach ($locale_arr as $locale_entry) {
            $res_str .= "\nLocale is : {$locale_entry}";
            $res_str .= "\n------------";
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\ndatetype = {$datetype_entry} ,timetype ={$datetype_entry}";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry);
                $pos = 0;
                $parsed = ut_datefmt_parse($fmt, $text_entry, $pos);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nParsed text is : {$parsed}; Position = {$pos}";
                } else {
                    $res_str .= "\nError while parsing as: '" . intl_get_error_message() . "'; Position = {$pos}";
                }
            }
        }
    }
    $res_str .= "\n";
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:29,代码来源:dateformat_parse_timestamp_parsepos.php


示例2: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $dateFormat = is_int($options['format']) ? $options['format'] : self::DEFAULT_FORMAT;
     $timeFormat = \IntlDateFormatter::NONE;
     $calendar = \IntlDateFormatter::GREGORIAN;
     $pattern = is_string($options['format']) ? $options['format'] : null;
     if (!in_array($dateFormat, self::$acceptedFormats, true)) {
         throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
     }
     if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) {
         throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
     }
     if ('single_text' === $options['widget']) {
         $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['model_timezone'], $options['view_timezone'], $dateFormat, $timeFormat, $calendar, $pattern));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array('error_bubbling' => true);
         $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, null, $calendar, $pattern);
         // new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
         if (!$formatter) {
             throw new InvalidOptionsException(intl_get_error_message(), intl_get_error_code());
         }
         $formatter->setLenient(false);
         if ('choice' === $options['widget']) {
             // Only pass a subset of the options to children
             $yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
             $yearOptions['choices_as_values'] = true;
             $yearOptions['placeholder'] = $options['placeholder']['year'];
             $yearOptions['choice_translation_domain'] = $options['choice_translation_domain']['year'];
             $monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
             $monthOptions['choices_as_values'] = true;
             $monthOptions['placeholder'] = $options['placeholder']['month'];
             $monthOptions['choice_translation_domain'] = $options['choice_translation_domain']['month'];
             $dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days']));
             $dayOptions['choices_as_values'] = true;
             $dayOptions['placeholder'] = $options['placeholder']['day'];
             $dayOptions['choice_translation_domain'] = $options['choice_translation_domain']['day'];
         }
         // Append generic carry-along options
         foreach (array('required', 'translation_domain') as $passOpt) {
             $yearOptions[$passOpt] = $monthOptions[$passOpt] = $dayOptions[$passOpt] = $options[$passOpt];
         }
         $builder->add('year', self::$widgets[$options['widget']], $yearOptions)->add('month', self::$widgets[$options['widget']], $monthOptions)->add('day', self::$widgets[$options['widget']], $dayOptions)->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], array('year', 'month', 'day')))->setAttribute('formatter', $formatter);
     }
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], array('year', 'month', 'day'))));
     }
 }
开发者ID:ron-testam,项目名称:symfony,代码行数:54,代码来源:DateType.php


示例3: convert

 /**
  * Parse data string and convert to the \DateTime object.
  *
  * @param string          $value
  * @param string|int|null $dateType
  * @param string|int|null $timeType
  * @param string|null     $locale
  * @param string|null     $timeZone
  * @param string|null     $pattern
  *
  * @return \DateTime|false
  */
 public function convert($value, $dateType = null, $timeType = null, $locale = null, $timeZone = null, $pattern = null)
 {
     if (!$locale) {
         $locale = $this->localeSettings->getLocale();
     }
     if (!$timeZone) {
         $timeZone = $this->localeSettings->getTimeZone();
     }
     if ($value) {
         $formatter = $this->getFormatter($dateType, $timeType, $locale, $timeZone, $pattern);
         $timestamp = $formatter->parse($value);
         if (intl_get_error_code() === 0) {
             return $this->getDateTime($timestamp);
         }
     }
     return false;
 }
开发者ID:antrampa,项目名称:platform,代码行数:29,代码来源:ExcelDateTimeTypeFormatter.php


示例4: ut_main

function ut_main()
{
    $res_str = '';
    $forms = array(Normalizer::FORM_C, Normalizer::FORM_D, Normalizer::FORM_KC, Normalizer::FORM_KD, Normalizer::NONE);
    $forms_str = array(Normalizer::FORM_C => 'UNORM_FORM_C', Normalizer::FORM_D => 'UNORM_FORM_D', Normalizer::FORM_KC => 'UNORM_FORM_KC', Normalizer::FORM_KD => 'UNORM_FORM_KD', Normalizer::NONE => 'UNORM_NONE');
    /* just make sure all the form constants are defined as in the api spec */
    if (Normalizer::FORM_C != Normalizer::NFC || Normalizer::FORM_D != Normalizer::NFD || Normalizer::FORM_KC != Normalizer::NFKC || Normalizer::FORM_KD != Normalizer::NFKD || Normalizer::NONE == Normalizer::FORM_C) {
        $res_str .= "Invalid normalization form declarations!\n";
    }
    $char_a_diaeresis = "ä";
    // 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4)
    $char_a_ring = "å";
    // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5)
    $char_o_diaeresis = "ö";
    // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6)
    $char_angstrom_sign = "Å";
    // 'ANGSTROM SIGN' (U+212B)
    $char_A_ring = "Å";
    // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
    $char_ohm_sign = "Ω";
    // 'OHM SIGN' (U+2126)
    $char_omega = "Ω";
    // 'GREEK CAPITAL LETTER OMEGA' (U+03A9)
    $char_combining_ring_above = "̊";
    // 'COMBINING RING ABOVE' (U+030A)
    $char_fi_ligature = "fi";
    // 'LATIN SMALL LIGATURE FI' (U+FB01)
    $char_long_s_dot = "ẛ";
    // 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B)
    $strs = array('ABC', $char_a_diaeresis . '||' . $char_a_ring . '||' . $char_o_diaeresis, $char_angstrom_sign . '||' . $char_A_ring . '||' . 'A' . $char_combining_ring_above, $char_ohm_sign . '||' . $char_omega, $char_fi_ligature, $char_long_s_dot);
    foreach ($forms as $form) {
        foreach ($strs as $str) {
            $str_norm = ut_norm_normalize($str, $form);
            $error_code = intl_get_error_code();
            $error_message = intl_get_error_message();
            $str_hex = urlencode($str);
            $str_norm_hex = urlencode($str_norm);
            $res_str .= "'{$str_hex}' normalized to form '{$forms_str[$form]}' is '{$str_norm_hex}'" . "\terror info: '{$error_message}' ({$error_code})\n" . "";
            $is_norm = ut_norm_is_normalized($str, $form);
            $error_code = intl_get_error_code();
            $error_message = intl_get_error_message();
            $res_str .= "\t\tis in form '{$forms_str[$form]}'? = " . ($is_norm ? "yes" : "no") . "\terror info: '{$error_message}' ({$error_code})\n" . "";
        }
    }
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:46,代码来源:normalizer_normalize.php


示例5: reverseTransform

 /**
  * Transforms a localized date string/array into a normalized date.
  *
  * @param  string|array $value Localized date string/array
  * @return DateTime Normalized date
  */
 public function reverseTransform($value)
 {
     $inputTimezone = $this->getOption('input_timezone');
     if (!is_string($value)) {
         throw new \InvalidArgumentException(sprintf('Expected argument of type string, %s given', gettype($value)));
     }
     $timestamp = $this->getIntlDateFormatter()->parse($value);
     if (intl_get_error_code() != 0) {
         throw new TransformationFailedException(intl_get_error_message());
     }
     // read timestamp into DateTime object - the formatter delivers in UTC
     $dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
     if ($inputTimezone != 'UTC') {
         $dateTime->setTimezone(new \DateTimeZone($inputTimezone));
     }
     return $dateTime;
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:23,代码来源:DateTimeToLocalizedStringTransformer.php


示例6: ut_main

function ut_main()
{
    $locale_arr = array('en_US_CA');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
    $res_str = '';
    $text_arr = array(array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("Wednesday, December 17, 1969 6:40:00 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("Thursday, December 18, 1969 8:49:59 PM PST", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::FULL), array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::NONE), array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::SHORT), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::NONE), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::SHORT), array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG), array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG));
    foreach ($text_arr as $text_entry) {
        $fmt = ut_datefmt_create('en_US_CA', $text_entry[1], $text_entry[2]);
        $parse_pos = 0;
        $parsed = ut_datefmt_parse($fmt, $text_entry[0], $parse_pos);
        $res_str .= "\nInput text : {$text_entry[0]} ; DF = {$text_entry[1]}; TF = {$text_entry[2]}";
        if (intl_get_error_code() != U_ZERO_ERROR) {
            $res_str .= "\nError : " . intl_get_error_message();
        }
        $res_str .= "\nParsed: {$parsed}; parse_pos : {$parse_pos}\n";
    }
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:dateformat_parse.php


示例7: format

 /**
  * Formats the message with the help of php intl extension.
  * 
  * @param string $locale
  * @param string $message
  * @param array(string=>mixed) $parameters
  * @return string
  * @throws CannotInstantiateFormatterException If the message pattern cannot be used.
  * @throws CannotFormatException If an error occurs during formatting.
  */
 public function format($locale, $message, array $parameters)
 {
     if (empty($message)) {
         // Empty strings are not accepted as message pattern by the \MessageFormatter.
         return $message;
     }
     try {
         $formatter = new \MessageFormatter($locale, $message);
     } catch (\Exception $e) {
         throw new CannotInstantiateFormatterException($e->getMessage(), $e->getCode(), $e);
     }
     if (!$formatter) {
         throw new CannotInstantiateFormatterException(intl_get_error_message(), intl_get_error_code());
     }
     $result = $formatter->format($parameters);
     if ($result === false) {
         throw new CannotFormatException($formatter->getErrorMessage(), $formatter->getErrorCode());
     }
     return $result;
 }
开发者ID:webfactory,项目名称:icu-translation-bundle,代码行数:30,代码来源:IntlFormatter.php


示例8: reverseTransform

 /**
  * Transforms a localized date string/array into a normalized date.
  *
  * @param  string|array $value Localized date string/array
  * @return DateTime Normalized date
  */
 public function reverseTransform($value)
 {
     $inputTimezone = $this->getOption('input_timezone');
     if (!is_string($value)) {
         throw new UnexpectedTypeException($value, 'string');
     }
     if ('' === $value) {
         return null;
     }
     $timestamp = $this->getIntlDateFormatter()->parse($value);
     if (intl_get_error_code() != 0) {
         throw new TransformationFailedException(intl_get_error_message());
     }
     // read timestamp into DateTime object - the formatter delivers in UTC
     $dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
     if ('UTC' != $inputTimezone) {
         $dateTime->setTimezone(new \DateTimeZone($inputTimezone));
     }
     return $dateTime;
 }
开发者ID:yproximite,项目名称:symfony-legacy-form,代码行数:26,代码来源:DateTimeToLocalizedStringTransformer.php


示例9: format

 /**
  * {@inheritdoc}
  */
 public function format($value, array $options = array())
 {
     if (null === $value) {
         return $options['null_value'];
     }
     if (!$value instanceof \DateTime) {
         throw FormatterException::invalidType($this, $value, 'DateTime instance');
     }
     $dateTime = clone $value;
     if ('UTC' !== $options['time_zone']) {
         $dateTime->setTimezone(new \DateTimeZone('UTC'));
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $options['date_format'], $options['time_format'], $options['time_zone'], $options['calendar'], $options['pattern']);
     $formatter->setLenient(false);
     $value = $formatter->format((int) $dateTime->format('U'));
     if (intl_is_failure(intl_get_error_code())) {
         throw FormatterException::intlError($this, intl_get_error_message());
     }
     $value = preg_replace('~GMT\\+00:00$~', 'GMT', $value);
     return $value;
 }
开发者ID:jfsimon,项目名称:datagrid,代码行数:24,代码来源:DateTimeFormatter.php


示例10: createDateTime

 /**
  * Creates date time object from date string
  *
  * @param string $dateString
  * @param string|null $timeZone
  * @param string $format
  * @throws \Exception
  * @return \DateTime
  */
 private function createDateTime($dateString, $timeZone = null, $format = 'yyyy-MM-dd')
 {
     $pattern = $format ? $format : null;
     if (!$timeZone) {
         $timeZone = date_default_timezone_get();
     }
     $calendar = \IntlDateFormatter::GREGORIAN;
     $intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, $timeZone, $calendar, $pattern);
     $intlDateFormatter->setLenient(false);
     $timestamp = $intlDateFormatter->parse($dateString);
     if (intl_get_error_code() != 0) {
         throw new \Exception(intl_get_error_message());
     }
     // read timestamp into DateTime object - the formatter delivers in UTC
     $dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
     if ('UTC' !== $timeZone) {
         try {
             $dateTime->setTimezone(new \DateTimeZone($timeZone));
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), $e->getCode(), $e);
         }
     }
     return $dateTime;
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:33,代码来源:DateRangeTypeTest.php


示例11: format

 /**
  * Formats a message via [ICU message format](http://userguide.icu-project.org/formatparse/messages)
  *
  * It uses the PHP intl extension's [MessageFormatter](http://www.php.net/manual/en/class.messageformatter.php)
  * and works around some issues.
  * If PHP intl is not installed a fallback will be used that supports a subset of the ICU message format.
  *
  * @param string $pattern The pattern string to insert parameters into.
  * @param array $params The array of name value pairs to insert into the format string.
  * @param string $language The locale to use for formatting locale-dependent parts
  * @return string|boolean The formatted pattern string or `FALSE` if an error occurred
  */
 public function format($pattern, $params, $language)
 {
     $this->_errorCode = 0;
     $this->_errorMessage = '';
     if ($params === []) {
         return $pattern;
     }
     if (!class_exists('MessageFormatter', false)) {
         return $this->fallbackFormat($pattern, $params, $language);
     }
     if (version_compare(PHP_VERSION, '5.5.0', '<') || version_compare(INTL_ICU_VERSION, '4.8', '<')) {
         // replace named arguments
         $pattern = $this->replaceNamedArguments($pattern, $params, $newParams);
         $params = $newParams;
     }
     $formatter = new \MessageFormatter($language, $pattern);
     if ($formatter === null) {
         $this->_errorCode = intl_get_error_code();
         $this->_errorMessage = "Message pattern is invalid: " . intl_get_error_message();
         return false;
     }
     $result = $formatter->format($params);
     if ($result === false) {
         $this->_errorCode = $formatter->getErrorCode();
         $this->_errorMessage = $formatter->getErrorMessage();
         return false;
     } else {
         return $result;
     }
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:42,代码来源:MessageFormatter.php


示例12: format

 /**
  * Formats a message via [ICU message format](http://userguide.icu-project.org/formatparse/messages)
  *
  * It uses the PHP intl extension's [MessageFormatter](http://www.php.net/manual/en/class.messageformatter.php)
  * and works around some issues.
  * If PHP intl is not installed a fallback will be used that supports a subset of the ICU message format.
  *
  * @param string $pattern The pattern string to insert parameters into.
  * @param array $params The array of name value pairs to insert into the format string.
  * @param string $language The locale to use for formatting locale-dependent parts
  * @return string|bool The formatted pattern string or `FALSE` if an error occurred
  */
 public function format($pattern, $params, $language)
 {
     $this->_errorCode = 0;
     $this->_errorMessage = '';
     if ($params === []) {
         return $pattern;
     }
     if (!class_exists('MessageFormatter', false)) {
         return $this->fallbackFormat($pattern, $params, $language);
     }
     // replace named arguments (https://github.com/yiisoft/yii2/issues/9678)
     $newParams = [];
     $pattern = $this->replaceNamedArguments($pattern, $params, $newParams);
     $params = $newParams;
     try {
         $formatter = new \MessageFormatter($language, $pattern);
         if ($formatter === null) {
             // formatter may be null in PHP 5.x
             $this->_errorCode = intl_get_error_code();
             $this->_errorMessage = 'Message pattern is invalid: ' . intl_get_error_message();
             return false;
         }
     } catch (\IntlException $e) {
         // IntlException is thrown since PHP 7
         $this->_errorCode = $e->getCode();
         $this->_errorMessage = 'Message pattern is invalid: ' . $e->getMessage();
         return false;
     } catch (\Exception $e) {
         // Exception is thrown by HHVM
         $this->_errorCode = $e->getCode();
         $this->_errorMessage = 'Message pattern is invalid: ' . $e->getMessage();
         return false;
     }
     $result = $formatter->format($params);
     if ($result === false) {
         $this->_errorCode = $formatter->getErrorCode();
         $this->_errorMessage = $formatter->getErrorMessage();
         return false;
     } else {
         return $result;
     }
 }
开发者ID:arogachev,项目名称:yii2,代码行数:54,代码来源:MessageFormatter.php


示例13: testParseIntl

 /**
  * @dataProvider parseProvider
  */
 public function testParseIntl($value, $expected, $message = '')
 {
     $this->skipIfIntlExtensionIsNotLoaded();
     $this->skipIfICUVersionIsTooOld();
     $formatter = $this->getIntlFormatterWithDecimalStyle();
     $parsedValue = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE);
     $this->assertSame($expected, $parsedValue, $message);
     if ($expected === false) {
         $errorCode = StubIntl::U_PARSE_ERROR;
         $errorMessage = 'Number parsing failed: U_PARSE_ERROR';
     } else {
         $errorCode = StubIntl::U_ZERO_ERROR;
         $errorMessage = 'U_ZERO_ERROR';
     }
     $this->assertSame($errorMessage, intl_get_error_message());
     $this->assertSame($errorCode, intl_get_error_code());
     $this->assertSame($errorCode > 0, intl_is_failure(intl_get_error_code()));
     $this->assertSame($errorMessage, $formatter->getErrorMessage());
     $this->assertSame($errorCode, $formatter->getErrorCode());
     $this->assertSame($errorCode > 0, intl_is_failure($formatter->getErrorCode()));
 }
开发者ID:navassouza,项目名称:symfony,代码行数:24,代码来源:StubNumberFormatterTest.php


示例14: ut_main

function ut_main()
{
    $timezone = 'GMT+05:00';
    $locale_arr = array('en_US');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM);
    $res_str = '';
    $time_arr = array(0, -1200000, 1200000, 2200000000, -2200000000, 90099999, 3600, -3600);
    $localtime_arr1 = array('tm_sec' => 24, 'tm_min' => 3, 'tm_hour' => 19, 'tm_mday' => 3, 'tm_mon' => 3, 'tm_year' => 105);
    $localtime_arr2 = array('tm_sec' => 21, 'tm_min' => 5, 'tm_hour' => 7, 'tm_mday' => 13, 'tm_mon' => 7, 'tm_year' => 205);
    $localtime_arr3 = array('tm_sec' => 11, 'tm_min' => 13, 'tm_hour' => 0, 'tm_mday' => 17, 'tm_mon' => 11, 'tm_year' => -5);
    $localtime_arr = array($localtime_arr1, $localtime_arr2, $localtime_arr3);
    //Test format and parse with a timestamp : long
    foreach ($time_arr as $timestamp_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput timestamp is : {$timestamp_entry}";
        $res_str .= "\n------------\n";
        foreach ($locale_arr as $locale_entry) {
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\nIntlDateFormatter locale= {$locale_entry} ,datetype = {$datetype_entry} ,timetype ={$datetype_entry} ";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone);
                $formatted = ut_datefmt_format($fmt, $timestamp_entry);
                $res_str .= "\nFormatted timestamp is : {$formatted}";
                $parsed = ut_datefmt_parse($fmt, $formatted);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nParsed timestamp is : {$parsed}";
                } else {
                    $res_str .= "\nError while parsing as: '" . intl_get_error_message() . "'";
                }
            }
        }
    }
    //Test format and parse with a localtime :array
    foreach ($localtime_arr as $localtime_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput localtime is : ";
        foreach ($localtime_entry as $key => $value) {
            $res_str .= "{$key} : '{$value}' , ";
        }
        $res_str .= "\n------------\n";
        foreach ($locale_arr as $locale_entry) {
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\nIntlDateFormatter locale= {$locale_entry} ,datetype = {$datetype_entry} ,timetype ={$datetype_entry} ";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone);
                $formatted1 = ut_datefmt_format($fmt, $localtime_entry);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nFormatted localtime_array is : {$formatted1}";
                } else {
                    $res_str .= "\nError while formatting as: '" . intl_get_error_message() . "'";
                }
                //Parsing
                $parsed_arr = ut_datefmt_localtime($fmt, $formatted1);
                if ($parsed_arr) {
                    $res_str .= "\nParsed array is: ";
                    foreach ($parsed_arr as $key => $value) {
                        $res_str .= "{$key} : '{$value}' , ";
                    }
                }
                /*
                				else{
                				    //$res_str .= "No values found from LocaleTime parsing.";
                				    $res_str .= "\tError : '".intl_get_error_message()."'";
                				}
                */
            }
        }
    }
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:68,代码来源:dateformat_format_parse.php


示例15: getIntlErrorCode

 protected function getIntlErrorCode()
 {
     return intl_get_error_code();
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:4,代码来源:IntlDateFormatterTest.php


示例16: renderPage

function renderPage()
{
    $LINKSDB = new LinkDB($GLOBALS['config']['DATASTORE'], isLoggedIn(), $GLOBALS['config']['HIDE_PUBLIC_LINKS'], $GLOBALS['redirector'], $GLOBALS['config']['REDIRECTOR_URLENCODE']);
    $updater = new Updater(read_updates_file($GLOBALS['config']['UPDATES_FILE']), $GLOBALS, $LINKSDB, isLoggedIn());
    try {
        $newUpdates = $updater->update();
        if (!empty($newUpdates)) {
            write_updates_file($GLOBALS['config']['UPDATES_FILE'], $updater->getDoneUpdates());
        }
    } catch (Exception $e) {
        die($e->getMessage());
    }
    $PAGE = new PageBuilder();
    $PAGE->assign('linkcount', count($LINKSDB));
    $PAGE->assign('privateLinkcount', count_private($LINKSDB));
    // Determine which page will be rendered.
    $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
    $targetPage = Router::findPage($query, $_GET, isLoggedIn());
    // Call plugin hooks for header, footer and includes, specifying which page will be rendered.
    // Then assign generated data to RainTPL.
    $common_hooks = array('includes', 'header', 'footer');
    $pluginManager = PluginManager::getInstance();
    foreach ($common_hooks as $name) {
        $plugin_data = array();
        $pluginManager->executeHooks('render_' . $name, $plugin_data, array('target' => $targetPage, 'loggedin' => isLoggedIn()));
        $PAGE->assign('plugins_' . $name, $plugin_data);
    }
    // -------- Display login form.
    if ($targetPage == Router::$PAGE_LOGIN) {
        if ($GLOBALS['config']['OPEN_SHAARLI']) {
            header('Location: ?');
            exit;
        }
        // No need to login for open Shaarli
        $token = '';
        if (ban_canLogin()) {
            $token = getToken();
        }
        // Do not waste token generation if not useful.
        $PAGE->assign('token', $token);
        if (isset($_GET['username'])) {
            $PAGE->assign('username', escape($_GET['username']));
        }
        $PAGE->assign('returnurl', isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : '');
        $PAGE->renderPage('loginform');
        exit;
    }
    // -------- User wants to logout.
    if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=logout')) {
        invalidateCaches($GLOBALS['config']['PAGECACHE']);
        logout();
        header('Location: ?');
        exit;
    }
    // -------- Picture wall
    if ($targetPage == Router::$PAGE_PICWALL) {
        // Optionally filter the results:
        $links = $LINKSDB->filterSearch($_GET);
        $linksToDisplay = array();
        // Get only links which have a thumbnail.
        foreach ($links as $link) {
            $permalink = '?' . escape(smallhash($link['linkdate']));
            $thumb = lazyThumbnail($link['url'], $permalink);
            if ($thumb != '') {
                $link['thumbnail'] = $thumb;
                // Thumbnail HTML code.
                $linksToDisplay[] = $link;
                // Add to array.
            }
        }
        $data = array('linksToDisplay' => $linksToDisplay);
        $pluginManager->executeHooks('render_picwall', $data, array('loggedin' => isLoggedIn()));
        foreach ($data as $key => $value) {
            $PAGE->assign($key, $value);
        }
        $PAGE->renderPage('picwall');
        exit;
    }
    // -------- Tag cloud
    if ($targetPage == Router::$PAGE_TAGCLOUD) {
        $tags = $LINKSDB->allTags();
        // We sort tags alphabetically, then choose a font size according to count.
        // First, find max value.
        $maxcount = 0;
        foreach ($tags as $value) {
            $maxcount = max($maxcount, $value);
        }
        // Sort tags alphabetically: case insensitive, support locale if avalaible.
        uksort($tags, function ($a, $b) {
            // Collator is part of PHP intl.
            if (class_exists('Collator')) {
                $c = new Collator(setlocale(LC_COLLATE, 0));
                if (!intl_is_failure(intl_get_error_code())) {
                    return $c->compare($a, $b);
                }
            }
            return strcasecmp($a, $b);
        });
        $tagList = array();
        foreach ($tags as $key => $value) {
//.........这里部分代码省略.........
开发者ID:toneiv,项目名称:Shaarli,代码行数:101,代码来源:index.php


示例17: var_dump

var_dump(idn_to_ascii("-foo.com", 0, INTL_IDNA_VARIANT_UTS46));
echo "\n", "empty domain:", "\n";
var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46, $info));
var_dump($info);
var_dump($info["errors"] == IDNA_ERROR_EMPTY_LABEL);
echo "\n", "domain too long (max allowed 253, trailing hyphen ignored):", "\n";
$result = idn_to_ascii(str_repeat("a.", 126) . "aa", 0, INTL_IDNA_VARIANT_UTS46, $info);
var_dump($result);
var_dump($info);
var_dump($info["errors"] == IDNA_ERROR_DOMAIN_NAME_TOO_LONG);
echo "\n", "buffer overflow:", "\n";
$result = idn_to_ascii(str_repeat("a", 2048), 0, INTL_IDNA_VARIANT_UTS46, $info);
var_dump($result);
var_dump($info);
var_dump(intl_get_error_code() == U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR);
echo "\n", "BiDi and CONTEXTJ errors:", "\n";
$result = idn_to_ascii(u("\\u0644\\u200C"), IDNA_NONTRANSITIONAL_TO_ASCII | IDNA_CHECK_BIDI | IDNA_CHECK_CONTEXTJ, INTL_IDNA_VARIANT_UTS46, $info);
var_dump($result);
var_dump($info);
var_dump($info["errors"] == (IDNA_ERROR_BIDI | IDNA_ERROR_CONTEXTJ));
echo "\n", "reverse, invalid Punycode:", "\n";
$result = idn_to_utf8("xn--0", 0, INTL_IDNA_VARIANT_UTS46, $info);
var_dump($result);
var_dump($info);
var_dump($info["errors"] == IDNA_ERROR_PUNYCODE);
echo "\n", "reverse, buffer overflow:", "\n";
$result = idn_to_utf8(str_repeat("a", 2048), 0, INTL_IDNA_VARIANT_UTS46, $info);
var_dump($result);
var_dump($info);
var_dump(intl_get_error_code() == U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR);
开发者ID:ezoic,项目名称:hhvm,代码行数:30,代码来源:idn-uts46-errors.php


示例18: _formatMessage

 /**
  * Does the actual formatting using the MessageFormatter class
  *
  * @param string $locale The locale in which the message is presented.
  * @param string|array $message The message to be translated
  * @param array $vars The list of values to interpolate in the message
  * @return string The formatted message
  * @throws \Aura\Intl\Exception\CannotInstantiateFormatter if any error occurred
  * while parsing the message
  * @throws \Aura\Intl\Exception\CannotFormat If any error related to the passed
  * variables is found
  */
 protected function _formatMessage($locale, $message, $vars)
 {
     // Using procedural style as it showed twice as fast as
     // its counterpart in PHP 5.5
     $result = MessageFormatter::formatMessage($locale, $message, $vars);
     if ($result === false) {
         // The user might be interested in what went wrong, so replay the
         // previous action using the object oriented style to figure out
         $formatter = new MessageFormatter($locale, $message);
         if (!$formatter) {
             throw new Exception\CannotInstantiateFormatter(intl_get_error_message(), intl_get_error_code());
         }
         $formatter->format($vars);
         throw new Exception\CannotFormat($formatter->getErrorMessage(), $formatter->getErrorCode());
     }
     return $result;
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:29,代码来源:IcuFormatter.php


示例19: format

 /**
  * 
  * Format the message with the help of php intl extension
  * 
  * @param string $locale
  * @param string $string
  * @param array $tokens_values
  * @return string
  * @throws Exception
  */
 public function format($locale, $string, array $tokens_values)
 {
     // extract tokens and retain sequential positions
     $tokens = [];
     $i = 0;
     // opening brace, followed by the token word characters,
     // followed by any non-token word character
     $regex = '/(\\{)([A-Za-z0-9_]+)([\\,\\}])/m';
     preg_match_all($regex, $string, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         // the token name
         $key = $match[2];
         if (!isset($tokens[$key])) {
             $tokens[$key] = $i;
             $num = $i;
             $i++;
         } else {
             $num = $tokens[$key];
         }
         // replace just the first occurence;
         // other occurrences will get replaced later.
         $string = preg_replace("/{$match['0']}/", '{' . $num . $match[3], $string, 1);
     }
     $values = [];
     foreach ($tokens as $token => $i) {
         if (!isset($tokens_values[$token])) {
             continue;
         }
         $value = $tokens_values[$token];
         // convert an array to a CSV string
         if (is_array($value)) {
             $value = '"' . implode('", "', $value) . '"';
         }
         $values[$i] = $value;
     }
     $formatter = new MessageFormatter($locale, $string);
     if (!$formatter) {
         throw new Exception\CannotInstantiateFormatter(intl_get_error_message(), intl_get_error_code());
     }
     $result = $formatter->format($values);
     if ($result === false) {
         throw new Exception\CannotFormat($formatter->getErrorMessage(), $formatter->getErrorCode());
     }
     return $result;
 }
开发者ID:fabioalvaro,项目名称:cakexuxu,代码行数:55,代码来源:IntlFormatter.php


示例20: ensure_collator_available

 /**
  * Ensures that a collator is available and created
  *
  * @return bool Returns true if collation is available and ready
  */
 protected static function ensure_collator_available()
 {
     $locale = get_string('locale', 'langconfig');
     if (is_null(self::$collator) || $locale != self::$locale) {
         self::$collator = false;
         self::$locale = $locale;
         if (class_exists('Collator', false)) {
             $collator = new Collator($locale);
             if (!empty($collator) && $collator instanceof Collator) {
                 // Check for non fatal error messages. This has to be done immediately
                 // after instantiation as any further calls to collation will cause
                 // it to reset to 0 again (or another error code if one occurred)
                 $errorcode = $collator->getErrorCode();
                 $errormessage = $collator->getErrorMessage();
                 // Check for an error code, 0 means no error occurred
                 if ($errorcode !== 0) {
                     // Get the actual locale being used, e.g. en, he, zh
                     $localeinuse = $collator->getLocale(Locale::ACTUAL_LOCALE);
                     // Check for the common fallback warning error codes. If any of the two
                     // following errors occurred, there is normally little to worry about:
             

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP intl_get_error_message函数代码示例发布时间:2022-05-15
下一篇:
PHP intl_get函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap