When we use ACCESS database and ASP to build websites, sometimes there may be garbled problems with UTF-8. So what should we do if the asp UTF-8 garbled problems occur? Now let’s take a look at the solution to the asp UTF-8 garbled problem.
This is a problem with web encoding. In Chinese, gb2312 is generally used, so if you show that Chinese is basically not garbled. But sometimes we use an internationally common utf-8 format. If people don’t know much about the utf-8 format, they are prone to garbled code.
Many friends have asked me why the codepage specified in ASP is 65001 and it often displays garbled codes. The talented man will explain this question in detail here to avoid many friends taking detours and even rejecting UTF-8.
Asp web page utf8 garbled code If you don’t know what UTF-8 is, then Caizi suggests that you search for UTF-8’s related information first.
It is certainly reasonable that UTF-8 encoding is accepted and even liked by more and more people. Today, when WEB2.0 is popular, while talking about multi-browser compatibility, I have to think that the garbled phenomenon caused by different character encodings also needs to be handled well...
N years ago, all versions below IE6 would be garbled if they did not have the corresponding font library installed. For example, I am the version of IE5 (Windows2000 default). Without the IE traditional font library installed, websites that access any traditional page will be garbled if they are not installed. Of course, the premise is that the page uses BIG5's Charset, and UTF-8 can handle this problem well as an international encoding. As long as the page is saved as UTF-8 encoding format, and then define codepage and charset as utf-8 on the page, you can display the completely correct content in any client browser and will not be garbled...
Okay, Caizi takes the ASP page as an example, and let’s take an example to see the specific operation:
In this case, Caizi recommended using Editplus to write code. Caizi also wrote a tutorial on using Editplus. Interested friends can click here to check it out.
Open a new ASP page, I believe that friends who play ASP will notice that in many downloaded source codes, there is usually a sentence at the top of the page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
There is no need to say much about the previous language. vbscript is the default scripting language for ASP. In fact, it is completely unnecessary to write. If written, it will also affect the page execution efficiency. We will not discuss this issue here. The codepage behind is the key, and the purpose is to tell the browser what kind of encoding this page is. 936 represents simplified Chinese, while 950 represents traditional Chinese, and 65001 is the UTF-8 encoding we are talking about today. We change 936 to 65001, and the whole sentence is as follows:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
Add a few Chinese characters to see if they can be displayed correctly.
<%
Response.Write "First Testing of UTF-8 Pages"
%>
OK, just click "Save" and execute this page to see. If nothing unexpected happens, you may see the words "One-tail UTF-8 page" that are displayed. There is garbled Chinese. What is the reason?
OK, please click on the "File" menu at the top and select "Save As". There is an encoding on the bottom line. The default should be ANSI. Please click the drop-down box, select UTF-8, click Save, and then try it. If nothing unexpected happens, it will be even more messy. Haha, I'm dizzy. Don't worry, think about the reason, because the page we made is returned by HTML. When we wrote HTML, we saw a sentence meta in front of the body, that is, the head, which should be like this:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
That is, the specified page returns the result with gb2312 encoding, and must be written before the output of the return result. Everyone knows that gb2312 is simplified Chinese. What we are talking about today is UTF-8 encoding. Let’s change gb2312 to UTF-8. The whole code is as follows:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%
Response.Write "First Testing of UTF-8 Pages"
%>
Execute again, well, it will be displayed normally this time...
Asp web page utf8 garbled conclusion: UTF-8 encoding is used. In addition to saving the file as UTF-8 format, you also need to specify codepage and charset at the same time.
The code that ensures that the asp leaf will not appear garbled should be like this:
(Assuming it is the leaf of UTF-8)
<%@ CODEPAGE=65001 %>
<% Response.CodePage=65001%>
<% Response.Charset="UTF-8" %>
You can create a public file code.asp, and all pages contain this encoding specification.
asp UTF-8 garbled code problem? After reading it, we can know that in fact, the solution to the garbled code of many data read by Ajax is the same. The solution principle is the same in asp.net, php and other languages.