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 #177204 is a reply to message #177182] Mon, 27 February 2012 09:34 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 25/02/2012 4:17, Basewind escribió/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/>

As far as I know, the only way is providing the full <?xml...?> tag in
the constructor:

$namesXML = new SimpleXMLElement('<?xml version="1.0"
encoding="utf-8"?><names></names>');
echo $namesXML->asXML();

SimpleXML will display the tag as-is (though it will not actually _use_
the encoding information). It'll use UTF-8 no matter what you type there.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[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: Thu Nov 28 05:31:14 GMT 2024

Total time taken to generate the page: 0.04727 seconds