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


PHP CharsetConverter::specCharsToASCII方法代碼示例

本文整理匯總了PHP中TYPO3\CMS\Core\Charset\CharsetConverter::specCharsToASCII方法的典型用法代碼示例。如果您正苦於以下問題:PHP CharsetConverter::specCharsToASCII方法的具體用法?PHP CharsetConverter::specCharsToASCII怎麽用?PHP CharsetConverter::specCharsToASCII使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TYPO3\CMS\Core\Charset\CharsetConverter的用法示例。


在下文中一共展示了CharsetConverter::specCharsToASCII方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: 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


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