0

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;
    }

I am writing text like this

And data will change like this

  • Am I correct to assume you're creating a `slug` as in a URL path, like http://example.com/my-slug-goes-here? You can save yourself a lot of heartache and potential bugs by retrieving the content as Text rather than HTML, see https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getcontent for more details. – Dallas Clark Jun 23 '20 at 23:34

4 Answers4

2

Did you try entity_encoding?

entity_encoding : "raw",

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

  • Actually i have seen this code. And i tried to use this in tinymce.min.js but i dont know is it correct or not. I just added this code end of tinymce.min.js – Sinan Sarıkaya Jun 23 '20 at 14:32
  • Try this code inside of tinymce.init function like the example on the link. – SerhatSoylemez Jun 23 '20 at 14:44
  • I tried like this. (Türksünüz sanırım. sinan.499@gmail.com mail atar mısınız?) tinymce.init({ selector: 'textarea', // change this value according to your HTML entity_encoding : "raw" }); – Sinan Sarıkaya Jun 23 '20 at 14:46
  • Using entity_encoding worked for me http://fiddle.tinymce.com/qmhaab/1 – Dallas Clark Jun 23 '20 at 23:30
1

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.

Michael Fromin
  • 13,131
  • 2
  • 20
  • 31
0

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);
0

Use numeric encoding. For example, it will encode ü to &#776 and will work perfectly.

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