There are mainly five aspects:
1. The problem of converting HTML pages to UTF-8 encoding
2. The problem of converting PHP pages to UTF-8 encoding
3. The problem of using UTF-8 encoding for MYSQL databases
4. JS Related UTF-8 encoding issues
5. FLASH related UTF-8 encoding issues
1. HTML page conversion to UTF-8 encoding issues
1. Add a line after
and beforeThe order cannot be wrong, and must be added before the
2.html file encoding problem:
Click the menu of the editor: "File"->"Save As", you can see the encoding of the current file, make sure the file encoding is: UTF-8, if it is ANSI, it is required Change the encoding to: UTF-8.
3. HTML file header BOM problem:
When converting files from other encodings to UTF-8 encoding, sometimes a BOM tag is added at the beginning of the file. The BOM tag may cause the browser to Garbled characters appear when displaying Chinese characters.
How to delete this BOM tag:
1. You can open the file with Dreamweaver and resave it to remove the BOM tag!
2. You can open the file with EditPlus, and in the menu "Preferences"->"File"->"UTF-8 Identity", set it to: "Always delete signatures", then save the file, and you can remove it. BOM tag!
4. WEB server UTF-8 encoding problem:
If you follow the steps listed above and still have Chinese garbled problems, please check the encoding problem of the WEB server you are using
If you are using Apache, please set the charset in the configuration file to: utf-8 (only the methods are listed here, please refer to the apache configuration file for the specific format).
If you are using Nginx, please set: charset in nginx.conf to utf-8, specifically find "charset " gb2312;" or similar statement, change it to: "charset utf-8;".
2. PHP page conversion to UTF-8 encoding problem
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 menu of the editor: "File"->"Save As", you can see Go to the encoding of the current file and make sure the file encoding is: UTF-8. If it is ANSI, you need to change the encoding to: UTF-8.
3. PHP file header BOM problem:
PHP files must not have BOM tags. Otherwise, there will be a situation where the session cannot be used, and there will be a similar prompt:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
This is because, while executing session_start() When , the entire page cannot be output, but because the BOM tag exists in the previous PHP page, PHP treats the BOM tag as output, so an error occurs!
So the BOM tag must be deleted on the PHP page
How to delete this BOM tag:
1. You can open the file with Dreamweaver and resave it to remove the BOM tag!
2. You can open the file with EditPlus, and in the menu "Preferences"->"File"->"UTF-8 Identity", set it to: "Always delete signatures", then save the file, and you can remove it. BOM tag!
4. UTF-8 encoding problem when PHP saves a file as an attachment:
When PHP saves a file as an attachment, the file name must be GB2312 encoded. Otherwise, if there is Chinese in the file name, it will be garbled:
If your PHP itself is a file in UTF-8 encoding format, you need to convert the file name variable from UTF-8 to GB2312:
iconv("UTF-8", "GB2312", "$filename");
5. When truncating and displaying the article title, garbled characters or "?" question marks appear:
Generally, when the article title is very long, part of the title will be displayed, and the article title will be truncated, because a UTF-8 encoded Chinese The characters will occupy 3 characters in width. When intercepting the title, sometimes only 1 character or 2 characters in width of a Chinese character will be intercepted. If the interception is not complete, garbled characters or "?" question marks will appear. Use the following function to intercept Title, there will be no problem:
function get_brief_str($str, $max_length) { echo strlen($str) ."<br>"; if(strlen($str) > $max_length) { $check_num = 0; for($i=0; $i < $max_length; $i++) { if (ord($str[$i]) > 128) $check_num++; } if($check_num % 3 == 0) $str = substr($str, 0, $max_length)."..."; else if($check_num % 3 == 1) $str = substr($str, 0, $max_length + 2)."..."; else if($check_num % 3 == 2) $str = substr($str, 0, $max_length + 1)."..."; } return $str; }
3. Problems with using UTF-8 encoding for MYSQL database
1. Use phpmyadmin to create databases and data tables
When creating a database, please set "Organization" to: "utf8_general_ci ” or execute the statement:
CREATE DATABASE `dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
When creating a data table: If the field stores Chinese, you need to set “Organization” to: “utf8_general_ci”,
If the field stores English or numbers, the default is fine .
The corresponding SQL statement, for example:
CREATE TABLE `test` ( `id` INT NOT NULL , `name` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM ;
2. Use PHP to read and write the database
After connecting to the database:
$connection = mysql_connect($host_name, $host_user, $host_pass);
Add two lines:
mysql_query("set character set 'utf8'");//读库 mysql_query("set names 'utf8'");//写库
Then you can read and write the MYSQL database normally.
4. UTF-8 encoding issues related to JS
1. Chinese garbled problem when JS reads cookies
PHP needs to escape encode Chinese characters when writing cookies, otherwise JS reads Chinese characters in cookies will be gibberish.
但php本身没有escape函数,我们新写一个escape函数:
function escape($str) { preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r); $ar = $r[0]; foreach($ar as $k=>$v) { if(ord($v[0]) < 128) $ar[$k] = rawurlencode($v); else $ar[$k] = "%u".bin2hex(iconv("UTF-8","UCS-2",$v)); } return join("",$ar); }
JS读cookie的时候,用unescape解码,然后就解决cookie中有中文乱码的问题了。
2.外部JS文件UTF-8编码问题
当一个HTML页面或则PHP页面包含一个外部的JS文件时,如果HTML页面或则PHP页面是UTF-8编码格式的文件,外部的JS文件同样要转成UTF-8的文件,否则将出现,没有包含不成功,调用函数时没有反应的情况。
点击编辑器的菜单:“文件”->“另存为”,可以看到当前文件的编码,确保文件编码为:UTF-8,如果是ANSI,需要将编码改成:UTF-8。
五.FLASH相关的UTF-8编码问题
FLASH内部对所有字符串,默认都是以UTF-8处理
1.FLASH读文普通本文件(txt,html)
要将文本文件的编码存为UTF-8
点击编辑器的菜单:“文件”->“另存为”,可以看到当前文件的编码,确保文件编码为:UTF-8,如果是ANSI,需要将编码改成:UTF-8。
2.FLASH读XML文件
要将XML文件的编码存为UTF-8
点击编辑器的菜单:“文件”->“另存为”,可以看到当前文件的编码,确保文件编码为:UTF-8,如果是ANSI,需要将编码改成:UTF-8。
在XML第1行写:
<?xml version="1.0" encoding="utf-8"?>
3.FLASH读PHP返回数据
如果PHP编码本身是UTF-8的,直接echo就可以了。
如果PHP编码本身是GB2312的,可以将PHP转存成UTF-8编码格式的文件,直接echo就可以了
如果PHP编码本身是GB2312的,而且不允许改文件的编码格式,用下面的语句将字符串转换成UTF-8的编码格式
$new_str = iconv("GB2312", "UTF-8", "$str");
再echo就可以了
4.FLASH读数据库(MYSQL)的数据
FLASH要通过PHP读取数据库中的数据,PHP本身的编码不重要,关键是如果数据库的编码是GB2312的话,需要用下面的语句将字符串转换成UTF-8的编码格式。
$new_str = iconv("GB2312", "UTF-8", "$str");
5.FLASH通过PHP写数据
一句话,FLASH传过来的字符串是UTF-8格式的,要转换成相应的编码格式,再操作(写文件、写数据库、直接显示等等),还是用iconv函数转换。
6.FLASH使用本地编码(理论上不推荐使用)
如果想让FLASH不使用UTF-8编码,而是使用本地编码。对于中国大陆地区而言,本地编码是GB2312或GBK
AS程序内,可以添加以下代码:
System.useCodepage = true;
那么FLASH内所有字符都是使用GB2312的编码了,所有导入到FLASH或者从FLASH导出的数据,都应该做相应的编码转换。
因为使用本地编码,会造成使用繁体中文地区的用户产生乱码,所以不推荐使用。
以上就是Web 开发中遇到的UTF-8编码的问题总结的内容,更多相关文章请关注PHP中文网(www.php.cn)!

译者 | 李睿审校 | 孙淑娟Web Speech API是一种Web技术,允许用户将语音数据合并到应用程序中。它可以通过浏览器将语音转换为文本,反之亦然。Web Speech API于2012年由W3C社区引入。而在十年之后,这个API仍在开发中,这是因为浏览器兼容性有限。该API既支持短时输入片段,例如一个口头命令,也支持长时连续的输入。广泛的听写能力使它非常适合与Applause应用程序集成,而简短的输入很适合语言翻译。语音识别对可访问性产生了巨大的影响。残疾用户可以使用语音更轻松地浏览

docker部署javaweb系统1.在root目录下创建一个路径test/appmkdirtest&&cdtest&&mkdirapp&&cdapp2.将apache-tomcat-7.0.29.tar.gz及jdk-7u25-linux-x64.tar.gz拷贝到app目录下3.解压两个tar.gz文件tar-zxvfapache-tomcat-7.0.29.tar.gztar-zxvfjdk-7u25-linux-x64.tar.gz4.对解

web端指的是电脑端的网页版。在网页设计中我们称web为网页,它表现为三种形式,分别是超文本(hypertext)、超媒体(hypermedia)和超文本传输协议(HTTP)。

区别:1、前端指的是用户可见的界面,后端是指用户看不见的东西,考虑的是底层业务逻辑的实现,平台的稳定性与性能等。2、前端开发用到的技术包括html5、css3、js、jquery、Bootstrap、Node.js、Vue等;而后端开发用到的是java、php、Http协议等服务器技术。3、从应用范围来看,前端开发不仅被常人所知,且应用场景也要比后端广泛的太多太多。

和它本身的轻便一样,Bottle库的使用也十分简单。相信在看到本文前,读者对python也已经有了简单的了解。那么究竟何种神秘的操作,才能用百行代码完成一个服务器的功能?让我们拭目以待。1. Bottle库安装1)使用pip安装2)下载Bottle文件https://github.com/bottlepy/bottle/blob/master/bottle.py2.“HelloWorld!”所谓万事功成先HelloWorld,从这个简单的示例中,了解Bottle的基本机制。先上代码:首先我们从b

web前端打包工具有:1、Webpack,是一个模块化管理工具和打包工具可以将不同模块的文件打包整合在一起,并且保证它们之间的引用正确,执行有序;2、Grunt,一个前端打包构建工具;3、Gulp,用代码方式来写打包脚本;4、Rollup,ES6模块化打包工具;5、Parcel,一款速度极快、零配置的web应用程序打包器;6、equireJS,是一个JS文件和模块加载器。

web有前端,也有后端。web前端也被称为“客户端”,是关于用户可以看到和体验的网站的视觉方面,即用户所看到的一切Web浏览器展示的内容,涉及用户可以看到,触摸和体验的一切。web后端也称为“服务器端”,是用户在浏览器中无法查看和交互的所有内容,web后端负责存储和组织数据,并确保web前端的所有内容都能正常工作。web后端与前端通信,发送和接收信息以显示为网页。

怎么解决高并发大流量问题?下面本篇文章就来给大家分享下高并发大流量web解决思路及方案,希望对大家有所帮助!


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
