开发者

UTF-8 encoding xml in PHP

开发者 https://www.devze.com 2023-01-24 13:49 出处:网络
I\'m trying to output XML using PHP, and when I look at the page source in Firefox everything seems fine. However, the page itself doesn\'t display properly.

I'm trying to output XML using PHP, and when I look at the page source in Firefox everything seems fine. However, the page itself doesn't display properly.

In Firefox, it usually says this at the top of the page when it's showing correctly formatted XML:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

..and then it shows the xml tree.

However, I just get the characters within the xml tags, and no tree.

The only difference I can see is that 开发者_StackOverflow社区my page is encoded as Western ISO-8859-1 and the correctly displayed XML is encoded as Unicode UTF-8. So how would I output my page as Unicode UTF8?

I've tried this but it doesn't make any difference:

echo utf8_encode($xmlstring);


Make sure you send the XML with an appropriate content-type and encoding, e.g.

<?php header("Content-Type: application/xml; charset=utf-8"); ?>

Also check that the XML prolog contains the proper encoding, e.g.

<?xml version="1.0" encoding="UTF-8"?>

The message about the style information refers to a missing processing instruction, e.g.

<?xml-stylesheet type="text/xsl" href="someting"?>

which would tell the browser how to style/format the output. It is not necessarily needed if you just want to display the raw XML.

0

精彩评论

暂无评论...
验证码 换一张
取 消