FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » simplexml adding 'encoding' attribute to xml declaration
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: simplexml adding 'encoding' attribute to xml declaration [message #177190 is a reply to message #177182] Sat, 25 February 2012 19:40 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Basewind wrote:

> I'm creating an xml file using simplexml, but would like to add the
> encoding="UTF-8" to the XML declaration. Like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> How can I do this?
>
> Here's my code:
>
> <?php
> $namesXML = new SimpleXMLElement("<names></names>");
> echo $namesXML->asXML();
>
> This shows:
>
> <?xml version="1.0" ?><!-- want the encoding attribute added here -->
> <names/>

It is called *Simple*XML*Element* for a reason. However, this particular
character encoding declaration is superfluous; UTF-8 is one of the XML
default encodings [1].

And do use header() to declare the XML media type that fits your data best.
Keep in mind that PHP's default is text/html which is not appropriate for
that kind of output.


PointedEars
___________
[1] <http://www.w3.org/TR/REC-xml/#charencoding>
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Is there a way to distinguish an auto-refresh from a manual page load?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Feb 26 08:31:16 GMT 2025

Total time taken to generate the page: 0.04202 seconds