Tutorial :Why are my \n not working in PHP?


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 = '';  }  


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.




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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »