UTF-8 coding ASP page output gb2312 (GBK) encoded variable super simple

Source: Internet
Author: User

My own page is coded in UTF-8. However, the problem is that on this page, a variable needs to be sent out after MD5 encryption, and the other party uses gb2312 encoding. This MD5 process contains Chinese variables, the encryption result is different from the encryption result of this variable. The reason is that the variable is the internal code of the UTF-8 when it is passed out, and the other party will explain it with gb2312 after receiving it. To solve this problem, you must convert the variable into gb2312 encoding before encryption.

 

I found n methods on the Internet, including utf2gb functions .. All of them are invalid or unsatisfactory. Some of them, although the encoding is successfully encrypted, are uploaded to the other party and the group is garbled.

 

Just as the mountains and waters are exhausted, we suddenly find that we can do this on the same page.CodeEncoding mode switch. This ensures that the code of the entire website page remains unchanged. You can use different encoding methods for a variable or part of the code segment on the page:

 

See the following page:

<% @ Language = "VBScript" codePage = "65001" %> <br/> <% <br/> response. code Page = 65001 <br/> response. charset = "UTF-8" <br/>%> <br/> <! -- # Include file = "md5.asp" --> <br/> <% <br/> dim A: A = "Chinese" <br/> dim B <br/> response. write (A & "<br>") <br/> B = MD5 (a) <br/> response. write (B & "<br>") </P> <p> 'start to change the encoding method <br/> response. code Page = 936 <br/> response. charset = "GBK" <br/> response. write (A & "<br>") <br/> B = MD5 (a) <br/> response. write (B & "<br>") </P> <p> 'Restore encoding method <br/> response. code Page = 65001 <br/> response. charset = "UTF-8" <br/> response. write (A & "<br>") <br/> B = MD5 (a) <br/> response. write (B & "<br>") <br/> %>

 

 

The running result is as follows: Garbled characters are actually the content of gb2312 encoding displayed on the UTF-8 page. If the receiver is gb2312, it can be correctly displayed.

 

Chinese
249ba6277758050695e8f5909bacd6d3
��
F3b679619b195beba139fcbb4b486630
Chinese
249ba6277758050695e8f5909bacd6d3

 

 

 

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.