Problem displaying international fonts with UTF-8

We have developed a PHP-MySQL application in two languages ​​- English and Gujarati. The Gujarati language contains characters that need Unicode UTF-8 encoding to display correctly.

The app works fine on my local windows machine and my Linux based test server on the internet.

But when I port my application to a client web server (based on linux redhat) Gujarati symbols are not displayed correctly.

I have checked the raw data from both databases (on my web server and client web server) - it is exactly the same. However, the display is different. On my server the fonts render fine, but when I try to access the client copy of the application, the Guajarati font display is wrong.

Since I am testing both of these installation instances from the same computer and the same browser, the issue is not browser incompatibility or code. I believe there are some server tweaks to be done that I am missing.

You can help.

thanks

Vinayak

UPDATE

Thanks. We tried the options for apache and php settings provided by members of the SO community. But the problem remains.

To solve the problem, we looked at the various stages of data flow.

The two databases (client side and our end) are identical. There is no difference in them.

The next step in this application is to execute a query that recovers the data, creates an xml file and saves it.

This XML file is then displayed on the PHP page.

We found that the problem was that there was a difference in the generated XML file. The code used to generate the XML file looks like this:

function fnCreateTestXML($testid)
{
    $objQuery = new clsQuery();
    $objTest = new clsTest();
    $setnames = $objQuery->fnSelectRecords("tbl_testsets", "setnumber", "");
    $queryresultstests = $objQuery->fnSelectRecords("tbl_tests", "", "");
    if($queryresultstests)
    {

        foreach($queryresultstests as $queryresulttest)
        {
            foreach($setnames as $setname)
            {
                //Creating Root node test and set its attribute 
                $doc = new DomDocument('1.0','utf-8');
                $root = $doc->createElement('test');
                $root = $doc->appendChild($root);
                //and so on

//Saving XML on the disk
                $xml_create = $doc->saveXML();
                $testname = "testsxml.xml";
                $xml_string = $doc->save($testname);

      

Any ideas?

thanks

Vinayak

0


a source to share


5 answers


Since you stated that it works in development environments and not your clients, you can check the Apache AddDefaultCharset clients and set that to UTF-8 if not already installed. (Let's assume they are using Apache.)

I try to follow the following steps:



  • PHP header sent in UTF-8
  • Meta tag is set to UTF-8 (Content-Type)
  • Storage is set to UTF-8
  • Server output is set to UTF-8
  • Make sure your php code files are UTF8 encoded using BOM (Byte Order Mark)
+2


a source


The answer almost certainly lies in sending headers from web pages. To diagnose such problems, I found it helpful to install the "Live HTTP Headers" Firefox addon .

Install this addon, then enable it and reload the page from the client web server and from your own.

What you will probably see is that the page served by your webserver has a header:

Content-Type: text/html; charset=UTF-8

      

Whereas when served by a client webserver, it says:



Content-Type: text/html

      

The way I would recommend this fix is ​​to make sure you explicitly set the header to specify utf-8 on every page of your application. This then insulates your application from future client-side configuration changes.

To do this, call

header('Content-type: text/html; charset=utf-8');

      

on every page before submitting any data.

+2


a source


Make sure the response headers are correct - the Content-type must be UTF-8.

0


a source


Check the character set settings in the DB instance on the client machine:

SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';

      

Before running any queries to select text, do the following:

SET NAMES utf8
SET CHARACTER SET utf8

      

If that works, you can add the following to my.cnf on the client machine:

[mysqld]
collation_server=utf8_unicode_ci
character_set_server=utf8
default-character-set=utf8
default-collation=utf8_general_ci
collation-server=utf8_general_ci

      

0


a source


Please use this meta tag: meta http-equiv = "Content-Type" content = "text / html; charset = UTF-8"

Make sure this code is used in php: mysql_query ("set character_set_results = 'utf8'");

0


a source







All Articles