Thai characters not displayed correctly in cms

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
thongchart
New Member
New Member
Posts: 2
Joined: Mon Jun 30, 2008 3:38 pm

Thai characters not displayed correctly in cms

Post by thongchart »

I made a custom defined tag for translating words from French to Thai and vice versa. While my code works fine on a standalone php page, once the code is run on cms page the Thai characters are replaced by funky characters.

My data is stored in the cms database that I changed to tis620 (table and column as well that stores the Thai script). I set on the global metadata charset=TIS-620 as well... still the Thai characters are not displayed properly. I tried many settings combination without success, don't know anymore where to look at given my poor knowledge.

For info the code:

If ($_POST['cboSearchType'] == 'ThaiWord')
$WordToShow = 'FrenchWord';
else $WordToShow = 'ThaiWord';

include("CustomPages/variables.inc.php");
mysql_connect($MySqlServer, $MySqlLogin, $MySqlPassword) or die(mysql_error());
mysql_select_db($MySqlDb) or die(mysql_error());
$charset="SET NAMES 'tis620'";
mysql_query($charset) or die('Invalid query: ' . mysql_error());
$Sql = "SELECT * FROM tblj_dic WHERE " . $_POST['cboSearchType'] . " = '" . $_POST['txtSearchCriteria'] . "'";
$SqlResult = mysql_query($Sql);

$Row = mysql_fetch_array($SqlResult);

mysql_close();
if ($Row[$WordToShow] == '')
echo 'Pas de resultat pour "' . $_POST['txtSearchCriteria'] . '"';
echo $Row[$WordToShow] . '' . $Row['Tone1'];

Help would be greatly appreciated!
thongchart
New Member
New Member
Posts: 2
Joined: Mon Jun 30, 2008 3:38 pm

Solved: Thai characters not displayed correctly in cms

Post by thongchart »

Found a solution... after changing in config.php the encoding to tis620, it was working, but then any Thai language stored in content_xx tables (even set as tis620 as well) was not displayed properly.

So what I did is restore utf8 as encoding everywhere (db, site settings). When querying the database from my custom page, I have to run this little query in order to get the correct encoding:

$charset="SET NAMES 'utf8'";
mysql_query($charset) or die('Invalid query: ' . mysql_error());

Now my Thai characters are displayed properly and can be queried in cms pages and custom pages. 
Post Reply

Return to “Developers Discussion”