PHP Tinymce土耳其语字符问题



我正在使用Tinymce编辑器。它工作正常,但是当我使用slug时,它无法正常工作 例如;当我写"Türkçe Ürün"时,我看到的结果是"t,uuml,rk,ccedil,e,uuml,r,uuml,n"像这样。

// Slugify a string
function slugify($text)
{
$text = str_replace('ü','u',$text);
$text = str_replace('Ü','U',$text);
$text = str_replace('ğ','g',$text);
$text = str_replace('Ğ','G',$text);
$text = str_replace('ş','s',$text);
$text = str_replace('Ş','S',$text);
$text = str_replace('ç','c',$text);
$text = str_replace('Ç','C',$text);
$text = str_replace('ö','o',$text);
$text = str_replace('Ö','O',$text);
$text = str_replace('ı','i',$text);
$text = str_replace('İ','I',$text);
// Strip html tags
$text=strip_tags($text);
// Replace non letter or digits by -
$text = preg_replace('~[^pLd]+~u', '-', $text);
// Transliterate
setlocale(LC_ALL, 'en_US.utf8');
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// Remove unwanted characters
$text = preg_replace('~[^-w]+~', '', $text);
// Trim
$text = trim($text, '-');
// Remove duplicate -
$text = preg_replace('~-+~', ',', $text);
// Lowercase
$text = strtolower($text);
// Check if it is empty
if (empty($text)) { return 'n-a'; }
// Return result
return $text;
}

我正在写这样的文字

数据会像这样变化

你试过entity_encoding吗?

entity_encoding : "raw",

https://www.tiny.cloud/docs/configure/content-filtering/#entity_encoding

如果您查看输入这些土耳其语字符时创建的 HTML,我怀疑您没有得到预期的内容,并且处理它的代码可能没有达到您的预期。

这些土耳其语字符不是正常 UTF-8 字符集(TinyMCE 默认值(的一部分,因此它们会被编码。 当我把你的内容放到TinyMCE中时,它会创建以下HTML:

Türkçe Ürün

请注意,这些土耳其字符中的每一个都是编码的 (http://fiddle.tinymce.com/qmhaab(。

您的服务器端代码似乎想要替换"非字母"字符并删除"不需要的"字符。 在我看来,您的代码正在破坏编码字符,因为与号 (&( 和分号 (;( 已从内容中删除。

谢谢你的回答。我已经解决了这段代码的问题。

$check_data = array('ü','Ü','ö','Ö','Ç','ç');
$change_data = array('ü','Ü','ö','Ö','Ç','ç'); 
$new_data = str_replace($check_data,$change_data,$description);

使用数字编码。例如,它将 ü 编码为 &#776 并且将完美运行。

tinymce.init({
.........................,
entity_encoding : 'numeric'
});

最新更新