Php output UTF-8 format XML file Chinese garbled problem (including asp, asp.net, jsp code)

Source: Internet
Author: User

The following is a situation where asp.net, php, jsp, and other languages need to add three bytes of content at the beginning of the output in UTF-8 output, so that the output file will not have any problems. I hope this will help you.

Using ASP. net c #

Response. ContentType = "text/xml; characterset = UTF-8 ";
Response. BinaryWrite (new byte [] {0xEF, 0xBB, 0xBF });

// Now write your XML data to output stream http://www.my400800.cn

Using ASP. NET VB

Response. ContentType = "text/xml"
Dim UTFHeader () As Byte ={& HEF, & HBB, & HBF}
Response. BinaryWrite (UTFHeader)

'Now write your XML data to output stream

Using PHP

Header ('content-type: text/xml ');
Echo pack ("C3", 0xef, 0xbb, 0xbf );

// Now write your XML data to output stream

Using ASP

Response. ContentType = "text/html"
Response. AddHeader "Content-Type", "text/html; charset = UTF-8"
Response. CodePage = 65001
Response. CharSet = "UTF-8"
Response. BinaryWrite (chrb (239 ))
Response. BinaryWrite (chrb (187 ))
Response. BinaryWrite (chrb (191 ))

'Now write your XML data to output stream

Using JSP


Response. setContentType ("text/xml; charset = UTF-8 ");
OutputStream outs = response. getOutputStream ();
Outs. write (new byte [] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF });

Outs. flush ();
// Now write your XML data to output stream

Using ColdFusion

Context = getPageContext ();
Response = context. getResponse (). getResponse ();
Out = response. getOutputStream ();

Out. write (1, 239 );
Out. write (1, 187 );
Out. write (1, 191 );

// Now write your XML data to output stream

Using ROR

Utf8_arr = [0xEF, 0xBB, 0xBF]
Utf8_str = utf8_arr.pack ("c3 ")

# Now write your XML data to output stream

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.