jdh Posted December 24, 2009 Share Posted December 24, 2009 Hey all, I have encountered something strange in a script. I am trying to write an XML header and then fill in the file: $xmlFile = "fetchableData.xml"; $fh = fopen($xmlFile, 'r+'); $housingData = updateHousingAndReturnXML(); $xmlData = '<?xml version="1.0" ?>'.$housingData; // echo $xmlData; fwrite($fh,$xmlData); fclose($fh); This code fills the file with the contents of $housingData, but <?xml version="1.0" ?> is not added. If I break up <? it will add it but then I get errors when parsing the XML. Echoing the string also doesn't work with <?. I guess what is happening is that the string is getting parsed by the PHP engine for some reason. Escaping <? doesn't work. I am assuming I am missing something basic. But the manual doesn't say anything about <? being parsed in strings. Help? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/ Share on other sites More sharing options...
rajivgonsalves Posted December 24, 2009 Share Posted December 24, 2009 does the string show up properly when you echo it ? what does updateHousingAndReturnXML do ? the only thing I can see that might go wrong is your using the same file handle for reading and writing so your reading and writing should be pretty accurate. Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-983799 Share on other sites More sharing options...
jdh Posted December 24, 2009 Author Share Posted December 24, 2009 echo '<?xml version="1.0" ?> returns nothing. updateHousingAndReturnXML() opens a webpage (using cURL), parses is with PCRE, and then returns a section of XML as a string. The XML returned by the function is stripped (doesn't give the information tags) so I am trying to add them by adding <xml version="1.0" ?> to the string before writing it to the file. Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-983819 Share on other sites More sharing options...
ignace Posted December 24, 2009 Share Posted December 24, 2009 Do you mean that it doesn't show up in view source or on-screen? Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-983820 Share on other sites More sharing options...
Buddski Posted December 24, 2009 Share Posted December 24, 2009 I would use something like this, its clean and simple. http://php.net/manual/en/class.domdocument.php Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-983855 Share on other sites More sharing options...
jdh Posted December 25, 2009 Author Share Posted December 25, 2009 echo '<?xml version="1.0" ?>' doesn't appear in the source (nor in rendered page). I DOMDocument builds XML files from a tree that you have already stored into a bunch of the DOM objects. It is a way to do it, but would involve rewriting a lot of functions like updateHousingAndReturnXML() that build xml sections as strings. Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-984020 Share on other sites More sharing options...
ignace Posted December 25, 2009 Share Posted December 25, 2009 Add this to your PHP script (very first line): ini_set('short_open_tag', false); Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-984031 Share on other sites More sharing options...
jdh Posted December 25, 2009 Author Share Posted December 25, 2009 @ignace: No love. echo '<?xml version="1.0" ?>' does nothing with short_open_tag turned off (and ini_get() confirms it was set properly). Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-984044 Share on other sites More sharing options...
Daniel0 Posted December 25, 2009 Share Posted December 25, 2009 If echo doesn't work it's probably because a fatal error is occurring before it. Check your error log or enable display_errors. Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-984086 Share on other sites More sharing options...
oni-kun Posted December 26, 2009 Share Posted December 26, 2009 Yeah, it should not parse as anything different. It works on my WAMP/online server echoing that string, but I have seen other people report this problem before.. Therefor I can conclude it's a server configuration issue of some sort. Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-984108 Share on other sites More sharing options...
jdh Posted December 26, 2009 Author Share Posted December 26, 2009 Thanks! In the config (via phpinfo) the only non-default option I found was safe_mode which was set to 1. Quote Link to comment https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/#findComment-984158 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.