Reputation: 9
i'm using tinymce editor. It's working normal but when im using slug, it's not working correctly For example; when i'm writing "Türkçe Ürün", i see the result "t,uuml,rk,ccedil,e,uuml,r,uuml,n" like this.
// 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('~[^\pL\d]+~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;
}
And data will change like this
Upvotes: 0
Views: 955
Reputation: 1
Use numeric encoding. For example, it will encode ü to ̈ and will work perfectly.
tinymce.init({
.........................,
entity_encoding : 'numeric'
});
Upvotes: 0
Reputation: 9
Thank you for all your answer. I have solved problem with this code.
$check_data = array('ü','Ü','ö','Ö','Ç','ç');
$change_data = array('ü','Ü','ö','Ö','Ç','ç');
$new_data = str_replace($check_data,$change_data,$description);
Upvotes: 0
Reputation: 13744
If you look at the HTML that gets created when you enter these Turkish characters I suspect you are not getting what you expect and your code to process it is likely not doing what you expect.
These Turkish characters are not part of the normal UTF-8 character set (the TinyMCE default) so they get encoded. When I put your content into TinyMCE it creates the following HTML:
Türkçe Ürün
Note that each of those Turkish characters is encoded (http://fiddle.tinymce.com/qmhaab).
Your server side code seems to want to replace "non-letter" characters and remove "unwanted" characters. It would appear to me that your code is breaking the encoded characters as the ampersand (&
) and semicolon (;
) have been removed from the content.
Upvotes: 1
Reputation: 126
Did you try entity_encoding?
entity_encoding : "raw",
https://www.tiny.cloud/docs/configure/content-filtering/#entity_encoding
Upvotes: 4