In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to solve the problem of Chinese garbled code when php is written into the database. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
The solution of php writing Chinese garbled code in the database: 1, create the database and set "utf8_general_ci" code; 2, read and write the database with PHP, and set "mysql_query (" set names' utf8' ");"
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem of garbled codes in php writing to database?
The problem of garbled codes in the database written by PHP
The problem of converting PHP pages to UTF-8 coding
1. Add a line at the beginning of the code:
Header ("Content-Type: text/html;charset=utf-8")
2.PHP file encoding problem
Click the editor menu: "File"-> "Save as", you can see the encoding of the current file, and make sure that the file is encoded as: UTF-8
If it is ANSI, you need to change the code to: UTF-8.
3.PHP header BOM problem:
PHP files must not have BOM tags
Otherwise, there will be a situation where session cannot be used with a similar prompt:
Warning: session_start () [function.session-start]: Cannot send session cache limiter-headers already sent
This is because when session_start () is executed, the entire page cannot have output, but when there is a BOM tag in the previous PHP page
PHP took this BOM tag as output, so it made a mistake!
So the BOM tag must be removed from the PHP page.
The method to delete this BOM tag:
1. You can use Dreamweaver to open the file, and re-save, that is, you can remove the BOM tag!
two。 You can open the file with EditPlus and set it to "always remove signatures" in the menu "preferences"-> "Files"-> "UTF-8 identity".
Then save the file, you can remove the BOM tag!
When 4.PHP saves the file as an attachment, the UTF-8 encoding problem:
PHP saves the file as an attachment, and the file name must be GB2312 encoded
Otherwise, if there is Chinese in the file name, the garbled code will be displayed:
If your PHP itself is a file in UTF-8 encoding format
You need to change the filename variable from UTF-8 to GB2312:
Iconv ("UTF-8", "GB2312", "$filename")
Use the program to exemplify the character interception method
Function utf8_substr ($str,$len) {for ($itemo / exchange i127) {$iodiac / if ($I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.