当前位置: 首页>>代码示例>>PHP>>正文


PHP Normalizer::normalize方法代码示例

本文整理汇总了PHP中Normalizer::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Normalizer::normalize方法的具体用法?PHP Normalizer::normalize怎么用?PHP Normalizer::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Normalizer的用法示例。


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

示例1: locate

 /**
  * Locate a source either if it a file or a directory and normalize it. Return an array of SplFileInfo.
  *
  * @param mixed $source
  * @return SplFileInfo[]
  * @throws Exception
  */
 public function locate($source)
 {
     $sources = [];
     $normalizedSources = [];
     // if the wildcard is at the end of the string, it means that we look for a directory
     $endingWithWilCard = substr($source, strlen($source) - 2) === '/*';
     if ($endingWithWilCard) {
         $source = substr($source, 0, strlen($source) - 2);
     }
     if (is_dir($source) || $endingWithWilCard) {
         $finder = new Finder();
         $finder->in($source);
         foreach ($finder as $file) {
             $sources[] = $file;
         }
     } else {
         if (strstr($source, '*') !== false) {
             // if the source contains a wildcard, we use it with the finder component
             $sources = $this->getSourcesFromFinder($source);
         } else {
             $sources[] = $source;
         }
     }
     // each found sources should be normalized
     foreach ($sources as $source) {
         $normalizedSources[] = $this->normalizer->normalize($source);
     }
     return $normalizedSources;
 }
开发者ID:johnkrovitch,项目名称:sam,代码行数:36,代码来源:Locator.php

示例2:

 /**
  * @covers Patchwork\PHP\Override\Mbstring::mb_strlen
  */
 function testmb_strlen()
 {
     $this->assertSame(3, mb_strlen('한국어'));
     $this->assertSame(8, mb_strlen(n::normalize('한국어', n::NFD)));
     $this->assertSame(3, p::mb_strlen('한국어'));
     $this->assertSame(8, p::mb_strlen(n::normalize('한국어', n::NFD)));
 }
开发者ID:nicolas-grekas,项目名称:Patchwork-sandbox,代码行数:10,代码来源:MbstringTest.php

示例3: message

 public static function message($publishHandler, eZContentObject $object, $message, $messageLength = null, $options)
 {
     $url = false;
     if (isset($options['include_url']) && (bool) $options['include_url'] === true) {
         $url = $object->attribute('main_node')->attribute('url_alias');
         eZURI::transformURI($url, true, 'full');
         if (isset($options['shorten_url']) && (bool) $options['shorten_url'] === true) {
             $urlReturned = $publishHandler->shorten($url, $options['shorten_handler']);
             if (is_string($urlReturned)) {
                 $url = $urlReturned;
             }
         }
         if ($messageLength != null) {
             $messageLength = $messageLength - strlen($url) - 1;
         }
     }
     if (class_exists('Normalizer')) {
         $message = Normalizer::normalize($message, Normalizer::FORM_C);
     }
     if ($messageLength != null) {
         $message = mb_substr($message, 0, $messageLength);
     }
     if ($url) {
         $message .= ' ' . $url;
     }
     return $message;
 }
开发者ID:sdaoudi,项目名称:nxc_social_networks,代码行数:27,代码来源:nxcSocialNetworksMessageHandlerDefault.php

示例4: __construct

 /**
  * Class constructor.
  *
  * @param mixed $string
  * @param string $encoding
  * @throws \InvalidArgumentException
  */
 public function __construct($string, $encoding = self::ENCODING)
 {
     if (is_null($string)) {
         $string = 'null';
     } elseif (is_bool($string)) {
         $string = $string ? 'true' : 'false';
     } elseif (is_int($string) || is_float($string)) {
         $string = (string) $string;
     } elseif (is_object($string)) {
         if (!method_exists($string, '__toString')) {
             throw new \InvalidArgumentException(sprintf('Object of class %s cannot be converted to String', get_class($string)));
         }
         $string = (string) $string;
     } elseif (!is_string($string)) {
         throw new \InvalidArgumentException('Cannot convert a variable of type ' . gettype($string) . ' to String');
     }
     if (!self::checkEncoding($encoding)) {
         throw new \InvalidArgumentException('Unsupported encoding: ' . $encoding);
     }
     if (!mb_check_encoding($string, $encoding)) {
         throw new \InvalidArgumentException('String is not encoded in ' . $encoding);
     }
     if ($encoding != self::ENCODING) {
         $string = mb_convert_encoding($string, self::ENCODING, $encoding);
     }
     $string = \Normalizer::normalize($string);
     $this->string = $string;
     $this->length = mb_strlen($string, self::ENCODING);
 }
开发者ID:e-ruiz,项目名称:brick,代码行数:36,代码来源:String.php

示例5: applyValue

 protected function applyValue($input, Context $ctx)
 {
     $output = $input;
     if ($input === null || $input === true || $input === false) {
         goto done;
     }
     if ($this->allowLoose) {
         $checkValue = $input;
         if (is_string($checkValue)) {
             $checkValue = mb_strtolower(\Normalizer::normalize($checkValue));
         }
         if (in_array($checkValue, $this->trueValues ?: self::$defaultLooseTrue, true)) {
             $output = true;
         } elseif (in_array($checkValue, $this->falseValues ?: self::$defaultLooseFalse, true)) {
             $output = false;
         }
     }
     if ($output !== false && $output !== true) {
         $ctx->addReason($this, ['id' => 'bool.invalid']);
     }
     done:
     if ($output !== $input) {
         $ctx->setChange(Change::Internal);
     }
     return $output;
 }
开发者ID:shabbyrobe,项目名称:fulfil,代码行数:26,代码来源:Bool_.php

示例6: simplify_strings

function simplify_strings($string)
{
    //Normalisation de la chaine utf8 en mode caractère + accents
    $string = Normalizer::normalize($string, Normalizer::FORM_D);
    //Suppression des accents et minuscules
    return strtolower(preg_replace('~\\p{Mn}~u', '', $string));
}
开发者ID:RadioCampusFrance,项目名称:podcast-rccf,代码行数:7,代码来源:search.php

示例7: testUnknown

 public function testUnknown()
 {
     $data = fopen('php://memory', 'rb');
     fclose($data);
     $normalized = $this->normalizer->normalize($data);
     $this->assertEquals('[unknown(' . gettype($data) . ')]', $normalized);
 }
开发者ID:interfasys,项目名称:lognormalizer,代码行数:7,代码来源:NormalizerTest.php

示例8:

 /**
  * @covers Patchwork\PHP\Override\Intl::grapheme_strlen
  */
 function testGrapheme_strlen()
 {
     $this->assertSame(3, grapheme_strlen('한국어'));
     $this->assertSame(3, grapheme_strlen(n::normalize('한국어', n::NFD)));
     $this->assertSame(3, p::grapheme_strlen('한국어'));
     $this->assertSame(3, p::grapheme_strlen(n::normalize('한국어', n::NFD)));
 }
开发者ID:nicolas-grekas,项目名称:Patchwork-sandbox,代码行数:10,代码来源:IntlTest.php

示例9: convertToValidCharacters

 /**
  * 入力を妥当な値に変換します。
  * @param string $input
  * @return string 変換できなかった場合は空文字列を返します。
  */
 protected function convertToValidCharacters(string $input) : string
 {
     $converted = preg_replace('/[\\p{C}\\p{Z}\\p{M}]+/u', '', \Normalizer::normalize(str_replace('~', '〜', $input), \Normalizer::FORM_KC));
     if ($this->isRegExp($converted)) {
         $converted = trim($converted, '/');
     }
     return $converted;
 }
开发者ID:esperecyan,项目名称:dictionary-php,代码行数:13,代码来源:AnswerValidator.php

示例10: asciify

function asciify($text)
{
    global $special_cases, $special_cases_keys;
    $text = Normalizer::normalize($text, Normalizer::FORM_C);
    $text = str_replace($special_cases_keys, $special_cases, $text);
    $text = Normalizer::normalize($text, Normalizer::FORM_D);
    return preg_replace('/[^\\x20-\\x7E]/', '', $text);
}
开发者ID:ox-it,项目名称:asciification,代码行数:8,代码来源:php.php

示例11: testStringUnicodeDifferentNormalisationEqual

 function testStringUnicodeDifferentNormalisationEqual()
 {
     $a = \Normalizer::normalize("ő", \Normalizer::FORM_KC);
     $b = \Normalizer::normalize("ő", \Normalizer::FORM_D);
     $this->assertNotEquals($a, $b);
     $flat = $this->compare($a, $b);
     $this->assertTrue($flat->valid);
 }
开发者ID:shabbyrobe,项目名称:fulfil,代码行数:8,代码来源:EqualTest.php

示例12: of

 /**
  * Public factory method.
  *
  * @param string $string
  *
  * @return UnicodeString
  *
  * @throws \InvalidArgumentException
  */
 public static function of(string $string)
 {
     if (!mb_check_encoding($string, 'UTF-8')) {
         throw new \InvalidArgumentException('String is not valid UTF-8');
     }
     $string = \Normalizer::normalize($string);
     $length = mb_strlen($string, 'UTF-8');
     return new UnicodeString($string, $length);
 }
开发者ID:brick,项目名称:type,代码行数:18,代码来源:UnicodeString.php

示例13: __construct

 /**
  * Class constructor.
  *
  * @param mixed $string
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(string $string)
 {
     if (!mb_check_encoding($string, 'UTF-8')) {
         throw new \InvalidArgumentException('String is not valid UTF-8');
     }
     $string = \Normalizer::normalize($string);
     $this->string = $string;
     $this->length = mb_strlen($string, 'UTF-8');
 }
开发者ID:brick,项目名称:brick,代码行数:16,代码来源:UnicodeString.php

示例14: unaccent

 /**
  * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297
  */
 public static function unaccent($string)
 {
     if (extension_loaded('intl') === true) {
         $string = \Normalizer::normalize($string, \Normalizer::FORM_KD);
     }
     if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false) {
         $string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|caron|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8');
     }
     return $string;
 }
开发者ID:bobbiebenton,项目名称:herbie,代码行数:13,代码来源:StringHelper.php

示例15: handlePost

 public function handlePost($postId, $post)
 {
     if (!$this->driverEnabled() || magnify_filter('disable_persist', false, $this->driver, $post) || !$this->isPersistablePostType($post) || $this->isAutosave() || $this->isAutoDraft($post)) {
         return;
     }
     if ($this->isPersistableStatus($post)) {
         $blogId = $this->getCurrentBlog();
         try {
             $this->driver->persist($blogId, $this->normalizer->normalize($blogId, $post));
             magnify_act('persisted_post', $blogId, $post);
         } catch (\Exception $e) {
             $this->logException($e, sprintf('persisting post #%d', $post->ID));
         }
     } else {
         // catches all non-published posts. Like trashed
         // or posts taht moved from published back to draft
         $this->handleDelete($post->ID);
     }
 }
开发者ID:WPMagnify,项目名称:core,代码行数:19,代码来源:SyncHandler.php


注:本文中的Normalizer::normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。