PHP page to UTF-8 Chinese encoding garbled solution _ php skills-php Tutorial

Source: Internet
Author: User
This article mainly introduces the php uft-8 Chinese encoding garbled solution, need friends can refer to the problem of garbled php developers will almost have encountered, the following describes php file garbled text and page garbled text.

PHP page to UTF-8 encoding problems
1. add a line at the beginning of the code:
Header ("Content-Type: text/html; charset = utf-8 ");
2. php file encoding problems
Click the editor menu: "File"-> "save as", you can see the current file encoding, make sure the file encoding: UTF-8,
If it is ANSI, you need to change the encoding to: UTF-8.
3. php file header BOM problems:
The PHP file cannot have BOM labels.
Otherwise, the session cannot be used, and a similar prompt is displayed:
Warning: session_start () [function. session-start]: Cannot send session cache limiter-headers already sent
This is because, when executing session_start (), the entire page cannot be output. However, because the former PHP page has a BOM label, PHP regards this BOM label as output, so an error occurred!
Therefore, you must delete the BOM label on the PHP page !!!
To delete this BOM tag:
1). you can use Dreamweaver to open the file and save it again, removing the BOM tag!
2). you can open the file with EditPlus, and in the menu "preferences"-> "files"-> "UTF-8 identity", set to "always delete signature ",
Save the file to remove the BOM label!
4. UTF-8 coding problems when PHP saves files in the form of attachments:
PHP saves the file as an attachment. the file name must be GB2312 encoded. Otherwise, if the file name contains Chinese characters, it will be garbled:
If your PHP itself is a UTF-8-encoded file, you need to convert the file name variable from the UTF-8 to GB2312:
Iconv ("UTF-8", "GB2312", "$ filename ");
How to use programs to intercept instance characters

function utf8_substr($str,$len) {   for($i=0;$i<$len;$i++)   {     $temp_str=substr($str,0,1);     if(ord($temp_str) > 127){       $i++;     if($i<$len){       $new_str[]=substr($str,0,3);       $str=substr($str,3);       }     }else {     $new_str[]=substr($str,0,1);     $str=substr($str,1);     }   }   return join($new_str); } 

The following article focuses on the use of MYSQL database UTF-8 coding issues, do not miss it.

The above is about php uft-8 Chinese encoding garbled solution, hope to help everyone to learn.

Related Article

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: 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.