Summary of zen-cart garbled characters

Source: Internet
Author: User

When using zen-cart to create e-commerce websites in multiple languages, garbled characters are often encountered. The following is a summary.

1. Database garbled issues. This problem may be caused by inconsistent page encoding when data is entered in the background and displayed in the foreground. For example, the background management used to input data encoding UTF-8, while the front-end display, encoding for iso-8859-7, will produce garbled. Work und: Set charset in the background Language Pack to iso-8859-7, or set charset in the foreground Language Pack to UTF-8. This method can be used for websites in a single language.

 

2. for multilingual sites, if you directly modify the site code to iso-8858-7, it may cause garbled problems in other languages. For example, the Greek Code is iso-8858-7, the Turkish Code is iso-8858-9, If you edit the product information in the Greek environment, then the encoding when entering the database is iso-8858-7, turkish language is also forced to input the database with the iso-8858-7 code, and at the front-end has to show the Turkish language with the iso-8858-9 code, so that the Turkish language may be garbled. Solution: All redundant multilingual sites adopt UTF-8 encoding format.

 

3. After UTF-8 encoding is adopted, because the files downloaded from the Online Language Pack are not in UTF-8 format, it may also cause garbled characters in some languages. Therefore, it is best to convert all downloaded language packs to the UTF-8 file format. You can use a text editor, dreamweaver, or another editor to convert each file in the Language Pack to the UTF-8 format. If you are in trouble, you can download an EncodingConvertor to encode all the files in a folder. Note that the original encoding must be correct. If you do not know the original encoding, open the language in the language Pack. php (replace the language with the language name, for example, english. php, greek. php) to see what the CHARSET definition is.

 

4. after the encoding is converted to UTF-8, the page may be wrong. This is because a unicode signature is automatically added at the beginning of the file when the file is saved in UTF-8 format (BOM, byte Order Mark), which is three invisible characters (0xEF 0xBB 0xBF), used to let some editing software (such as NotePad) know that the file is UTF-8 encoded. Php does not ignore these characters when require is encoded with UTF-8. As a result, these characters are part of the output. In this case, if the webpage layout is normal, remove the BOM, use dreamweaver to open the file, press ctrl + J, and deselect "including Unicode signature" on the title/encoding tab ", save it. You can also use the following code to batch process the BOM in a folder (put the following files in the root directory and click here ).

 

 

Code

<? Php
// This file is used to quickly test whether the UTF-8 encoded file is added with BOM and can be automatically removed.
// By Bob Shen
Require ('regiondes/application_top.php ');
$ Basedir = DIR_FS_CATALOG. 'supported des/ages '; // modify the directory to be detected for this behavior. The vertex indicates the current directory.
$ Auto = 1; // whether to automatically remove the detected BOM. 1 is yes, 0 is no.
Handler ($ basedir );
Function handler ($ dir ){
Global $ auto;

If ($ dh = opendir ($ dir )){
While ($ file = readdir ($ dh ))! = False ){
If ($ file! = '.' & $ File! = '..'){
If (! Is_dir ($ dir. "/". $ file )){
Echo "filename: $ dir/$ file". checkBOM ("$ dir/$ file"). "<br> ";
}
Else {
Handler ($ dir. "/". $ file );
}
}
}
Closedir ($ dh );
}
}
Function checkBOM ($ filename ){
Global $ auto;
$ Contents = file_get_contents ($ filename );
$ Charset [1] = substr ($ contents, 0, 1 );
$ Charset [2] = substr ($ contents, 1, 1 );
$ Charset [3] = substr ($ contents, 2, 1 );
If (ord ($ charset [1]) = 239 & ord ($ charset [2]) = 187 & ord ($ charset [3]) = 191) {
If ($ auto = 1 ){
$ Rest = substr ($ contents, 3 );
Rewrite ($ filename, $ rest );
Return ("<font color = red> BOM found, automatically removed. </font> ");
} Else {
Return ("<font color = red> BOM found. </font> ");
}
}
Else return ("BOM Not Found .");
}

Function rewrite ($ filename, $ data ){
$ Filenum = fopen ($ filename, "w ");
Flock ($ filenum, LOCK_EX );
Fwrite ($ filenum, $ data );
Fclose ($ filenum );
}
?>

 

After performing the preceding steps, no garbled characters are found.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.