Ask your Symfony questions! Pay money and get answers fast! (more info)

Handling Turkish characters Symfony

  • SOLVED

I do not have much experience with internationalization, so I'll post this here. Unsal discovered a bug in WordPress and [[LINK href="http://core.trac.wordpress.org/ticket/12361"]]posted a ticket on the WordPress site[[/LINK]]. The bug involves Turkish characters. Then [[LINK href="http://www.wpquestions.com/question/show/id/220"]]he posted it to our WordPress site[[/LINK]] (which is built using Symfony) and found that his Turkish characters were not coming through. This is perhaps a matter of character encoding? What encoding do I need to set to allow his characters to come through on our WordPress site?

Answers (4)

2010-03-01

Kiril Angov answers:

You need to make sure you database table use UTF-8. I am sure you use same HTML sanitizer for the input box to make sure you allow only the whitelisted tags, so make sure it is UTF-8 safe. Also try with other UTF-8 characters and see if they work.

2010-03-01

Gert Findel answers:

Kiril is right about utf-8 encoding for the database and the site. Utf-8 is enough for Turkish

It looks like you are using like the slugify method from the jobeet tutorial [[LINK href="http://www.symfony-project.org/jobeet/1_2/Propel/en/08"]]chapter 8[[/LINK]] (because its a permalink)

// code derived from http://php.vrana.cz/vytvoreni-pratelskeho-url.php
static public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);

// trim
$text = trim($text, '-');

// transliterate
if (function_exists('iconv'))
{
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
}

// lowercase
$text = strtolower($text);

// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);

if (empty($text))
{
return 'n-a';
}

return $text;
}


You might want to check that and correct properly not replacing the non-utf-8.


Gert Findel comments:

Kiril is right about utf-8 encoding for the database and the site. Utf-8 is enough for Turkish

It looks like you are using like the slugify method from the jobeet tutorial [[LINK href="http://www.symfony-project.org/jobeet/1_2/Propel/en/08"]]chapter 8[[/LINK]] (because its a permalink)

// code derived from http://php.vrana.cz/vytvoreni-pratelskeho-url.php
static public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);

// trim
$text = trim($text, '-');

// transliterate
if (function_exists('iconv'))
{
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
}

// lowercase
$text = strtolower($text);

// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);

if (empty($text))
{
return 'n-a';
}

return $text;
}


You might want to check that and correct properly not replacing the non-utf-8.