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


PHP Charset\CharsetConverter类代码示例

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


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

示例1: cleanFileName

 /**
  * Returns a string where any character not matching [.a-zA-Z0-9_-] is substituted by '_'
  * Trailing dots are removed
  *
  * @param string $fileName Input string, typically the body of a filename
  * @param string $charset Charset of the a filename (defaults to current charset; depending on context)
  * @return string Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_' and trailing dots removed
  * @todo Deprecate, but still in use by the core
  * @deprecated but still in use in the Core. Don't use in your extensions!
  */
 public function cleanFileName($fileName, $charset = '')
 {
     // Handle UTF-8 characters
     if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
         // allow ".", "-", 0-9, a-z, A-Z and everything beyond U+C0 (latin capital letter a with grave)
         $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . ']/u', '_', trim($fileName));
     } else {
         // Get conversion object or initialize if needed
         if (!is_object($this->csConvObj)) {
             $this->csConvObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
         }
         // Define character set
         if (!$charset) {
             if (TYPO3_MODE == 'FE') {
                 $charset = $GLOBALS['TSFE']->renderCharset;
             } else {
                 // Backend
                 $charset = 'utf-8';
             }
         }
         // If a charset was found, convert filename
         if ($charset) {
             $fileName = $this->csConvObj->specCharsToASCII($charset, $fileName);
         }
         // Replace unwanted characters by underscores
         $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . '\\xC0-\\xFF]/', '_', trim($fileName));
     }
     // Strip trailing dots and return
     return rtrim($cleanFileName, '.');
 }
开发者ID:vip3out,项目名称:TYPO3.CMS,代码行数:40,代码来源:BasicFileUtility.php

示例2: handleCharset

 /**
  * Converts the subject and the expected result into utf-8.
  *
  * @param string $subject the subject, will be modified
  * @param string $expected the expected result, will be modified
  */
 protected function handleCharset(&$subject, &$expected)
 {
     $charsetConverter = new CharsetConverter();
     $subject = $charsetConverter->conv($subject, 'iso-8859-1', 'utf-8');
     $expected = $charsetConverter->conv($expected, 'iso-8859-1', 'utf-8');
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:12,代码来源:ContentObjectRendererTest.php

示例3: convertToSafeString

 /**
  * Converts a given string to a string that can be used as a URL segment.
  * The result is not url-encoded.
  *
  * @param string $string
  * @param string $spaceCharacter
  * @return string
  */
 public function convertToSafeString($string, $spaceCharacter = '-')
 {
     $processedTitle = $this->csConvertor->conv_case('utf-8', $string, 'toLower');
     $processedTitle = strip_tags($processedTitle);
     $processedTitle = preg_replace('/[ \\-+_]+/', $spaceCharacter, $processedTitle);
     $processedTitle = $this->csConvertor->specCharsToASCII('utf-8', $processedTitle);
     $processedTitle = preg_replace('/[^\\p{L}0-9' . preg_quote($spaceCharacter) . ']/u', '', $processedTitle);
     $processedTitle = preg_replace('/' . preg_quote($spaceCharacter) . '{2,}/', $spaceCharacter, $processedTitle);
     $processedTitle = trim($processedTitle, $spaceCharacter);
     // TODO Post-processing hook here
     $processedTitle = strtolower($processedTitle);
     return $processedTitle;
 }
开发者ID:MaxServ,项目名称:typo3-realurl,代码行数:21,代码来源:Utility.php

示例4: isValid

 /**
  * Check if $value is valid. If it is not valid, needs to add an error
  * to result.
  *
  * @param mixed $value
  * @return void
  */
 public function isValid($value)
 {
     $length = $this->charsetConverter->strlen('utf-8', $value);
     if ($length < (int) $this->options['minimum']) {
         $this->addError($this->renderMessage($this->options['errorMessage'][0], $this->options['errorMessage'][1], 'error'), 1441999425);
         return;
     }
     if (!isset($this->options['maximum']) || $this->options['maximum'] === '') {
         $this->options['maximum'] = null;
     }
     if ($this->options['maximum'] !== null && $length > (int) $this->options['maximum']) {
         $this->addError($this->renderMessage($this->options['errorMessage'][0], $this->options['errorMessage'][1], 'error'), 1441999425);
     }
 }
开发者ID:rickymathew,项目名称:TYPO3.CMS,代码行数:21,代码来源:LengthValidator.php

示例5: isValid

 /**
  * Returns TRUE if submitted value validates according to rule
  *
  * @return bool
  * @see \TYPO3\CMS\Form\Validation\ValidatorInterface::isValid()
  */
 public function isValid()
 {
     if ($this->requestHandler->has($this->fieldName)) {
         $value = $this->requestHandler->getByMethod($this->fieldName);
         $length = $this->charsetConverter->strlen('utf-8', $value);
         if ($length < $this->minimum) {
             return FALSE;
         }
         if ($this->maximum !== NULL && $length > $this->maximum) {
             return FALSE;
         }
     }
     return TRUE;
 }
开发者ID:plan2net,项目名称:TYPO3.CMS,代码行数:20,代码来源:LengthValidator.php

示例6: JScharCode

 /**
  * Converts the input string to a JavaScript function returning the same string, but charset-safe.
  * Used for confirm and alert boxes where we must make sure that any string content
  * does not break the script AND want to make sure the charset is preserved.
  * Originally I used the JS function unescape() in combination with PHP function
  * rawurlencode() in order to pass strings in a safe way. This could still be done
  * for iso-8859-1 charsets but now I have applied the same method here for all charsets.
  *
  * @param string $str Input string, encoded with UTF-8
  * @return string Output string, a JavaScript function: "String.fromCharCode(......)
  * @depreacted since 6.2 - will be removed two versions later; use GeneralUtility::quoteJSvalue() instead
  */
 public function JScharCode($str)
 {
     GeneralUtility::logDeprecatedFunction();
     // Convert the UTF-8 string into a array of char numbers:
     $nArr = $this->csConvObj->utf8_to_numberarray($str);
     return 'String.fromCharCode(' . implode(',', $nArr) . ')';
 }
开发者ID:Mr-Robota,项目名称:TYPO3.CMS,代码行数:19,代码来源:LanguageService.php

示例7: startHandler

 /**
  * Handler for the opening of a tag
  */
 public function startHandler($xml_parser, $tag, $attributes)
 {
     if ((string) $this->xmlCharacterData !== '') {
         $this->spellCheckHandler($xml_parser, $this->xmlCharacterData);
         $this->xmlCharacterData = '';
     }
     switch ($tag) {
         case 'spellchecker':
             break;
         case 'br':
         case 'BR':
         case 'img':
         case 'IMG':
         case 'hr':
         case 'HR':
         case 'area':
         case 'AREA':
             $this->text .= '<' . $this->csConvObj->conv_case($this->parserCharset, $tag, 'toLower') . ' ';
             foreach ($attributes as $key => $val) {
                 $this->text .= $key . '="' . $val . '" ';
             }
             $this->text .= ' />';
             break;
         default:
             $this->text .= '<' . $this->csConvObj->conv_case($this->parserCharset, $tag, 'toLower') . ' ';
             foreach ($attributes as $key => $val) {
                 $this->text .= $key . '="' . $val . '" ';
             }
             $this->text .= '>';
     }
 }
开发者ID:adrolli,项目名称:TYPO3.CMS,代码行数:34,代码来源:SpellCheckingController.php

示例8: isValid

 /**
  * Check if $value is valid. If it is not valid, needs to add an error
  * to result.
  *
  * @param mixed $value
  * @return void
  */
 public function isValid($value)
 {
     if (empty($value) || !is_string($value)) {
         return;
     }
     $allowedOptionsArray = GeneralUtility::trimExplode(',', $this->options['array'], true);
     if (!empty($this->options['ignorecase'])) {
         $value = $this->charsetConverter->conv_case('utf-8', $value, 'toLower');
         foreach ($allowedOptionsArray as &$option) {
             $option = $this->charsetConverter->conv_case('utf-8', $option, 'toLower');
         }
     }
     if (!in_array($value, $allowedOptionsArray, !empty($this->options['strict']))) {
         $this->addError($this->renderMessage($this->options['errorMessage'][0], $this->options['errorMessage'][1], 'error'), 1442002594);
     }
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:23,代码来源:InArrayValidator.php

示例9: setCharsets

 /**
  * Sets character sets for the language key.
  *
  * @param string $languageKey
  * @param string $charset
  * @return void
  */
 protected function setCharsets($languageKey, $charset)
 {
     $this->sourceCharset = $this->csConvObj->parse_charset($this->csConvObj->charSetArray[$languageKey] ? $this->csConvObj->charSetArray[$languageKey] : 'utf-8');
     if ($charset) {
         $this->targetCharset = $this->csConvObj->parse_charset($charset);
     } else {
         $this->targetCharset = 'utf-8';
     }
 }
开发者ID:nicksergio,项目名称:TYPO3v4-Core,代码行数:16,代码来源:LocallangArrayParser.php

示例10: bodyDescription

 /**
  * Extracts the sample description text from the content array.
  *
  * @param array Content array
  * @return string Description string
  */
 public function bodyDescription($contentArr)
 {
     // Setting description
     $maxL = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->conf['index_descrLgd'], 0, 255, 200);
     if ($maxL) {
         $bodyDescription = str_replace(array(' ', TAB, CR, LF), ' ', $contentArr['body']);
         // Shorten the string:
         $bodyDescription = $this->csObj->strtrunc('utf-8', $bodyDescription, $maxL);
     }
     return $bodyDescription;
 }
开发者ID:plan2net,项目名称:TYPO3.CMS,代码行数:17,代码来源:Indexer.php

示例11: searchClubs

 /**
  * search records.
  *
  * @param string $search
  *
  * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
  */
 public function searchClubs($search)
 {
     // strtolower is not UTF-8 compatible
     // $search = strtolower($search);
     $longStreetSearch = $search;
     $smallStreetSearch = $search;
     // unify street search
     if (strtolower($this->charsetConverter->utf8_substr($search, -6) === 'straße')) {
         $smallStreetSearch = str_ireplace('straße', 'str', $search);
     }
     if (strtolower($this->charsetConverter->utf8_substr($search, -4)) === 'str.') {
         $longStreetSearch = str_ireplace('str.', 'straße', $search);
         $smallStreetSearch = str_ireplace('str.', 'str', $search);
     }
     if (strtolower($this->charsetConverter->utf8_substr($search, -3)) === 'str') {
         $longStreetSearch = str_ireplace('str', 'straße', $search);
     }
     $query = $this->createQuery();
     return $query->matching($query->logicalOr($query->like('title', '%' . $search . '%'), $query->like('sortTitle', '%' . $search . '%'), $query->like('addresses.street', '%' . $longStreetSearch . '%'), $query->like('addresses.street', '%' . $smallStreetSearch . '%'), $query->like('addresses.zip', '%' . $search . '%'), $query->like('addresses.city', '%' . $search . '%'), $query->like('contactPerson', '%' . $search . '%'), $query->like('description', '%' . $search . '%'), $query->like('tags', '%' . $search . '%')))->execute();
 }
开发者ID:jweiland-net,项目名称:clubdirectory,代码行数:27,代码来源:ClubRepository.php

示例12: encodeCharacter

 /**
  * Returns backslash encoded numeric format. Does not use backslash
  * character escapes such as, \" or \' as these may cause parsing problems.
  * For example, if a javascript attribute, such as onmouseover, contains
  * a \" that will close the entire attribute and allow an attacker to inject
  * another script attribute.
  *
  * @param string $character utf-8 character that needs to be encoded
  * @return string encoded character
  */
 protected function encodeCharacter($character)
 {
     if ($this->isImmuneCharacter($character)) {
         return $character;
     }
     $ordinalValue = $this->charsetConversion->utf8CharToUnumber($character);
     // Check for alphanumeric characters
     $hex = $this->getHexForNonAlphanumeric($ordinalValue);
     if ($hex === NULL) {
         return $character;
     }
     // Encode up to 256 with \\xHH
     if ($ordinalValue < 256) {
         $pad = substr('00', strlen($hex));
         return '\\x' . $pad . strtoupper($hex);
     }
     // Otherwise encode with \\uHHHH
     $pad = substr('0000', strlen($hex));
     return '\\u' . $pad . strtoupper($hex);
 }
开发者ID:nicksergio,项目名称:TYPO3v4-Core,代码行数:30,代码来源:JavaScriptEncoder.php

示例13: ordermoveSendMail

    /**
     * This method converts an sends mails.
     *
     * @param array $mailconf Mail configuration
     * @param array $orderdata Order data
     * @param string $template Template
     *
     * @return bool of \TYPO3\CMS\Core\Mail\MailMessage
     */
    protected function ordermoveSendMail(array $mailconf, array &$orderdata, &$template)
    {
        // First line is subject
        $parts = explode(chr(10), $mailconf['plain']['content'], 2);
        // add mail subject
        $mailconf['alternateSubject'] = trim($parts[0]);
        // replace plaintext content
        $mailconf['plain']['content'] = trim($parts[1]);
        /**
         * Convert Text to charset
         */
        $this->csConvObj->initCharset('utf-8');
        $this->csConvObj->initCharset('8bit');
        $mailconf['plain']['content'] = $this->csConvObj->conv($mailconf['plain']['content'], 'utf-8', 'utf-8');
        $mailconf['alternateSubject'] = $this->csConvObj->conv($mailconf['alternateSubject'], 'utf-8', 'utf-8');
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php']['ordermoveSendMail'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php\'][\'ordermoveSendMail\']
				is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Hook/OrdermailHooks.php\'][\'ordermoveSendMail\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php']['ordermoveSendMail'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postOrdermoveSendMail')) {
                    $hookObj->postOrdermoveSendMail($mailconf, $orderdata, $template);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/OrdermailHooks.php']['ordermoveSendMail'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/OrdermailHooks.php']['ordermoveSendMail'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postOrdermoveSendMail')) {
                    $hookObj->postOrdermoveSendMail($mailconf, $orderdata, $template);
                }
            }
        }
        return Tx_Commerce_Utility_GeneralUtility::sendMail($mailconf);
    }
开发者ID:AndreasA,项目名称:commerce,代码行数:48,代码来源:OrdermailHooks.php

示例14: addWords

 /**
  * Add word to word-array
  * This function should be used to make sure CJK sequences are split up in the right way
  *
  * @param 	array		Array of accumulated words
  * @param 	string		Complete Input string from where to extract word
  * @param 	integer		Start position of word in input string
  * @param 	integer		The Length of the word string from start position
  * @return 	void
  * @todo Define visibility
  */
 public function addWords(&$words, &$wordString, $start, $len)
 {
     // Get word out of string:
     $theWord = substr($wordString, $start, $len);
     // Get next chars unicode number and find type:
     $bc = 0;
     $cp = $this->utf8_ord($theWord, $bc);
     list($cType) = $this->charType($cp);
     // If string is a CJK sequence we follow this algorithm:
     /*
     		DESCRIPTION OF (CJK) ALGORITHMContinuous letters and numbers make up words. Spaces and symbols
     		separate letters and numbers into words. This is sufficient for
     		all western text.CJK doesn't use spaces or separators to separate words, so the only
     		way to really find out what constitutes a word would be to have a
     		dictionary and advanced heuristics. Instead, we form pairs from
     		consecutive characters, in such a way that searches will find only
     		characters that appear more-or-less the right sequence. For example:ABCDE => AB BC CD DEThis works okay since both the index and the search query is split
     		in the same manner, and since the set of characters is huge so the
     		extra matches are not significant.(Hint taken from ZOPEs chinese user group)[Kasper: As far as I can see this will only work well with or-searches!]
     */
     if ($cType == 'cjk') {
         // Find total string length:
         $strlen = $this->csObj->utf8_strlen($theWord);
         // Traverse string length and add words as pairs of two chars:
         for ($a = 0; $a < $strlen; $a++) {
             if ($strlen == 1 || $a < $strlen - 1) {
                 $words[] = $this->csObj->utf8_substr($theWord, $a, 2);
             }
         }
     } else {
         // Normal "single-byte" chars:
         // Remove chars:
         foreach ($this->lexerConf['removeChars'] as $skipJoin) {
             $theWord = str_replace($this->csObj->UnumberToChar($skipJoin), '', $theWord);
         }
         // Add word:
         $words[] = $theWord;
     }
 }
开发者ID:khanhdeux,项目名称:typo3test,代码行数:50,代码来源:Lexer.php

示例15: ordermoveSendMail

 /**
  * This method converts an sends mails.
  *
  * @param array $mailconf Mail configuration
  * @param array $orderdata Order data
  * @param string $template Template
  *
  * @return bool of \TYPO3\CMS\Core\Mail\MailMessage
  */
 protected function ordermoveSendMail(array $mailconf, array &$orderdata, &$template)
 {
     // First line is subject
     $parts = explode(chr(10), $mailconf['plain']['content'], 2);
     // add mail subject
     $mailconf['alternateSubject'] = trim($parts[0]);
     // replace plaintext content
     $mailconf['plain']['content'] = trim($parts[1]);
     /*
      * Convert Text to charset
      */
     $this->csConvObj->initCharset('utf-8');
     $this->csConvObj->initCharset('8bit');
     $mailconf['plain']['content'] = $this->csConvObj->conv($mailconf['plain']['content'], 'utf-8', 'utf-8');
     $mailconf['alternateSubject'] = $this->csConvObj->conv($mailconf['alternateSubject'], 'utf-8', 'utf-8');
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Hook/OrdermailHooks', 'ordermoveSendMail');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'postOrdermoveSendMail')) {
             $hook->postOrdermoveSendMail($mailconf, $orderdata, $template);
         }
     }
     return \CommerceTeam\Commerce\Utility\GeneralUtility::sendMail($mailconf);
 }
开发者ID:BenjaminBeck,项目名称:commerce,代码行数:32,代码来源:OrdermailHooks.php


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