Jump to content

Problems with strings containing <?


jdh

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/186286-problems-with-strings-containing/
Share on other sites

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.

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.