Adding a line break in PHP feed output

Adam Jones
Adam Jones used Ask the Experts™
on
Hello

I am trying to edit a feed that is created for my blog extension. I want to place a line break after each tag (there is another problem with the feed and bugs are hard to find when it is all on one line) but I cannot get it to work. I have tried /n but this just outputs /n.

It is not echo so I am not sure this is correct to use. Here is the code

            $output  = '<?xml version="1.0" encoding="UTF-8" ?>';
            $output .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';

Open in new window


I have tried

            $output  = '<?xml version="1.0" encoding="UTF-8" ?> /n';
            $output .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> /n';

Open in new window


this just outputs

<?xml version="1.0" encoding="UTF-8" ?>/n<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> /n

I have also tried

            $output  = '<?xml version="1.0" encoding="UTF-8" ?>';
			$output  = "\n";
            $output .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
			$output  = "\n";

Open in new window


This makes these lines disappear and replaced with a single line break.

Can someone please give me some advice?

Many Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Your second code sample was closest, but it should be:
$output  .= "\n";

The .= operator means append / concatenate

Author

Commented:
Thanks. Worked perfectly.
Most Valuable Expert 2011
Top Expert 2016

Commented:
Just a note for going forward, some OS do not use \n for the end-of-line character.  PHP has a context-aware, future-proof, end-of-line character available in a predefined constant: PHP_EOL
http://php.net/manual/en/reserved.constants.php

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial