williamZanelli Posted August 15, 2010 Share Posted August 15, 2010 Hi guys, I'm constructing a PHP document, using SimpleXML- I want to set the encolding of the document to "ISO-8859-1" - how do I do this.. This prob is driving me nuts... Can someone please help? Thanks in advance. Will Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/ Share on other sites More sharing options...
MadTechie Posted August 15, 2010 Share Posted August 15, 2010 The encoding should already be set in the XML, SimpleXML only converts XML to an object Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/#findComment-1099530 Share on other sites More sharing options...
williamZanelli Posted August 15, 2010 Author Share Posted August 15, 2010 Its not set, The only thing is says is - <?xml version="1.0"?> Not entirely sure how I can add the encoding to this. Surely its possible? They have it in this example - http://www.w3schools.com/PHP/func_simplexml__construct.asp Thanks in advance for your thoughts. Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/#findComment-1099554 Share on other sites More sharing options...
MadTechie Posted August 15, 2010 Share Posted August 15, 2010 SimpleXML is for reading XML not writing.updating/changing xml, DomDocument will allow you to change it, but your also need up encode the node's correctly, why exactly are you trying got do and why ? Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/#findComment-1099587 Share on other sites More sharing options...
williamZanelli Posted August 15, 2010 Author Share Posted August 15, 2010 Basically, I'm reading some XML, parsing from one source, and based on this and some other atrributes from my DB, I'm constructing a new XML document. Here's some sample code.. $output = new SimpleXMLElement("<root></root>"); //Add other child nodes etc.. file_put_contents($this->filePath, $output->asXML()); Any idea how I could chnage the encoding of the outputed file? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/#findComment-1099654 Share on other sites More sharing options...
MadTechie Posted August 15, 2010 Share Posted August 15, 2010 what do you mean your adding node ? SimpleXML doesn't add nodes it can't create them! any-ways if you just extracting parts then instead of re-writing it with a DomDocument, you could cheat! file_put_contents($this->filePath, preg_replace('/<\?xml [^>]*>/im', '<?xml version="1.0" encoding="ISO-8859-1" ?>', $output->asXML()); Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/#findComment-1099662 Share on other sites More sharing options...
williamZanelli Posted August 16, 2010 Author Share Posted August 16, 2010 Awesome stuff MadTechie.. works like charm :D Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/#findComment-1099681 Share on other sites More sharing options...
MadTechie Posted August 16, 2010 Share Posted August 16, 2010 Your welcome, please mark as solved (I'll do it this time ) Quote Link to comment https://forums.phpfreaks.com/topic/210779-simplexmlelement-encoding/#findComment-1099692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.