dongsi1944 2011-03-14 20:45
浏览 47
已采纳

将数据编码为UTF-8

I am getting an encoding error from an XML file generated from a XMLWriter. However I am sure that I can fix this error by converting the data from whatever encoding it is at the moment to UTF-8 encoding.

I would be greatful if you could tell me how to do this.

The error is

This page contains the following errors:

error on line 2 at column 721: Encoding error
Below is a rendering of the page up to the first error.

The code on line 2 at column 721 is <street>Mall CafÈ</street>.

My code to do this is:

$xml = new XMLWriter();

$xml->openURI("stores.xml");
$xml->startDocument("1.0");
$xml->startElement("stores");

while ($row = mysql_fetch_assoc($res)) {
$xml->startElement("store");
  $xml->startElement("type");

  $xml->writeRaw($row['type']);

  $xml->endElement();

 $xml->startElement("name");

  $xml->writeRaw($row['name']);

  $xml->endElement();

   $xml->startElement("street");

  $xml->writeRaw($row['street']);

  $xml->endElement();

   $xml->startElement("address1");

  $xml->writeRaw($row['address1']);

  $xml->endElement();

   $xml->startElement("address2");

  $xml->writeRaw($row['address2']);

  $xml->endElement();

   $xml->startElement("county");

  $xml->writeRaw($row['county']);

  $xml->endElement();

   $xml->startElement("postcode");

  $xml->writeRaw($row['postcode']);

  $xml->endElement();

   $xml->startElement("number");

  $xml->writeRaw($row['number']);

  $xml->endElement();

   $xml->startElement("latlong");

  $xml->writeRaw($row['latlong']);

  $xml->endElement();
  $xml->endElement();
}

$xml->endElement();
$xml->endDocument();
header ("Content-Type: text/xml");
$xml->flush();
?>
  • 写回答

1条回答 默认 最新

  • douji9184 2011-03-14 22:24
    关注
                $writer->startDocument("1.0", "UTF-8");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?