本文整理汇总了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;
}
示例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, '.');
}