Forum Moderators: coopster

Message Too Old, No Replies

problems using new line character

"\n" character not behaving as expected

         

dbarasuk

10:26 pm on Jan 27, 2008 (gmt 0)

10+ Year Member



Hi
Can somebody tell me why the "\n" does not send the next content to the next line ?

In the following code, i expect to get the words
"Connected"
"Disconnected" in this order, the next one under the first one, but i am getting "Connected""Disconnected" on the same line (which i was not expecting)

How can I force it.

Sorry, i know it's very basic but becoming tricky.

Here is the sample code:

<?php
// connect.php-connect to the MySQL server
if(!$conn_id=@mysql_connect("localhost", "$user", "$pass"))
{
die("cannot connect to server\n");
}

else {
print("Connected\n");
}

if(!@mysql_select_db("some_database")){
die("Cannot select database\n");
}

mysql_close();
print("Disconnected\n");

?>

cameraman

10:36 pm on Jan 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I imagine if you look at the html source you'll see that they're on separate lines, but remember, html isn't too impressed by newlines. Use <p>Connected</p> or <br> after each line on which you want a break.

dbarasuk

11:57 pm on Jan 27, 2008 (gmt 0)

10+ Year Member



thank you cameram;
it worked using your suggestion

ChainsawXIV

3:14 am on Jan 28, 2008 (gmt 0)

10+ Year Member



It's also worth noting that windows expects \n\r at the end of a line, where as *nix just uses \n. This isn't an issue in most situations, but it can cause some confusion depending on what you're looking at.