程序输出urf-8编码的xml文件中文(汉字)乱码问题解决方法

本文详细介绍了如何在ASP.NET、PHP、JSP等语言中输出UTF-8编码,并在输出开始添加必要的字节,确保文件显示无误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

asp.net,php,jsp等语言在输出utf-8是需要在输出开始添加三个字节的内容,不让输出的文件会有一定的问题,希望对大家有所帮助。

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

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(239);
        out.write(187);
        out.write(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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值