0

I'm playing with SAX and noticed it's not line breaking properly. I have no iea why.

function flush_data() {

    global $level, $char_data;

    $char_data = trim($char_data);

    if( strlen( $char_data ) > 0 ) {

        print "\n";


        $data = split("\n", wordwrap($char_data, 76 - ($level*2)));
        foreach($data as $line) {
            print str_repeat(' ', ($level +1)) . "[".$line."]"."\n";
        }
    }

    $char_data = '';
}
hakre
  • 193,403
  • 52
  • 435
  • 836
Strawberry
  • 66,024
  • 56
  • 149
  • 197

3 Answers3

4

Maybe you can try

print PHP_EOL;

It almost goes without saying, if you're doing this in a web page you need

header('Content-Type: text/plain');

\r\n is incorrect, PHP_EOL is the correct way to get a platform-independent newline.

Joshua
  • 215
  • 1
  • 7
-1

try

\r\n

return and new line feed work different on a windows and linux machine.

Glycerine
  • 7,157
  • 4
  • 39
  • 65
-2

I am an absolute beginner so I have no idea why
worked when I tried to solve a similar problem in my VERY simply php script. Give it a try. My code:

    $myfavmovie = urlencode("Life of Brian"); 
echo "Welcome back {$_SESSION['username']}";
echo "<br>";
echo "<a href='userseggs.php?favmovie=$myfavmovie'>
        Click here to see information about the eggs in your incubator"; 
echo "</a>";

Using any other newline tag/character didn't work. Hope it helps.