Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding line breaks to a text / xml file 1

Status
Not open for further replies.

stinkybee

Programmer
May 15, 2001
218
GB
I am creating an xml file and want it to format correctly when it is viewed. I have tried adding "\n" to the string but this just adds "\n" to the file. Does anyone know how I can add line breaks to my file.

example:

Code:
$strXML  = '<?xml version="1.0" ?>'
$strXML .= '<element>'
etc ....

produces '<?xml version="1.0" ?><element> etc....'

Code:
$strXML  = '<?xml version="1.0" ?>\n'
$strXML .= '<element>'
etc ....

produces '<?xml version="1.0" ?>\n<element> etc....'

 
two ways:
use double quotes instead of single quotes
Code:
$strXML  = "<?xml version=\"1.0\" ?>\";
$strXML .= "<element>";

or (my preferred despite the speed hit) use heredoc syntax:
Code:
$strXML  = <<<EOL
<?xml version="1.0" ?>
<element>
  <sub-element>
  </sub-element>
</element>

EOL;
 
Thanks for that, I wish I'd asked first and not spent several hours googling for a solution :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top