當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。