Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #5008
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="ISO-8859-1" |
| Message-ID | <1355583.WGnKmheAe9@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <php@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Sat, 25 Feb 2012 20:40:33 +0100 |
| User-Agent | KNode/4.4.11 |
| Content-Transfer-Encoding | 7Bit |
| Subject | Re: simplexml adding 'encoding' attribute to xml declaration |
| Newsgroups | comp.lang.php |
| References | <23370133.287.1330139868500.JavaMail.geo-discussion-forums@pbcqw3> |
| Followup-To | comp.lang.php |
| MIME-Version | 1.0 |
| Lines | 37 |
| NNTP-Posting-Date | 25 Feb 2012 20:40:34 CET |
| NNTP-Posting-Host | b33ecf44.newsspool3.arcor-online.net |
| X-Trace | DXC=j8Z?dMPgQ3VAX0F2i><W:SMcF=Q^Z^V3X4Fo<]lROoRQ8kF<OcfhCO[ln[0CFce16ZDZm8W4\YJN\b@mF9jNikdU0N0Tg=^RAQ\OJn8Y<ENaM[ |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.php:5008 |
Followups directed to: comp.lang.php
Show key headers only | View raw
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
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
simplexml adding 'encoding' attribute to xml declaration Basewind <mike@pearl-group.com> - 2012-02-24 19:17 -0800 Re: simplexml adding 'encoding' attribute to xml declaration Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-25 20:40 +0100 Re: simplexml adding 'encoding' attribute to xml declaration "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-02-27 10:34 +0100
csiph-web