neo777ph Posted February 27, 2007 Share Posted February 27, 2007 help. I would like to echo: <? echo "test\n" . "test2"; ?> as far as i know the output should be: test test2 i switched the auto_detect_line_endings into ON..to fix the problem..But it still does not fix the problem..I need the new line for my logging system. please help me. Quote Link to comment Share on other sites More sharing options...
ashly Posted February 27, 2007 Share Posted February 27, 2007 Use : <? echo "test<br>" . "test2"; ?> Quote Link to comment Share on other sites More sharing options...
neo777ph Posted February 27, 2007 Author Share Posted February 27, 2007 i did that already.. ok to be more straight.. => thus <br> be interpreted by a field on my MY_sql db as a new lineb \n.. So when it is inserted in the database.. it would be: test test2 Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 27, 2007 Share Posted February 27, 2007 use the nl2br() function to change the strings \n to the br tag. here is an example. $string = "This is a string with a \n newline in it."; //newline string. $string = nl2br($string); echo $string; //The string will now be properly formatted Quote Link to comment Share on other sites More sharing options...
neo777ph Posted February 27, 2007 Author Share Posted February 27, 2007 thx for the nl2br().. just want to confirm would \n be interpreted by my_sql as new line..So when it is inserted on the field.. it would be.. example: $test = "test \n test2"; the database field would take it as : test test2 Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 27, 2007 Share Posted February 27, 2007 yes, as far as i know mysql inserts new line data as a new line. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 27, 2007 Share Posted February 27, 2007 To be safe, I would use mysql_real_escape_string() before inserting the data to mysql. Then you can be sure that ANY character will be correctly stored (any that is supported by the underlying data type that is. Binary data will need mysql's binary data type, which I forgot the name of. But \n is still ok for text/varchar data). Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 27, 2007 Share Posted February 27, 2007 This depends on your OS - *nix uses \n (I think) Windows uses \r\n Quote Link to comment Share on other sites More sharing options...
Jenk Posted February 27, 2007 Share Posted February 27, 2007 This depends on your OS - *nix uses \n (I think) Windows uses \r\n It depends on your choice of encoding to be more precise. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 27, 2007 Share Posted February 27, 2007 no mater what OS you use MySQL will store the the newline. It just when you send newline charactersw (\r\n, \r or \n) to a web browser it will just ignore them - They are still there but can only be viewed from source. In order to get the browser to display them you need to use the HTML line breaks (<br />). It best to use nl2br when getting data out of the database, not when inserting it into the database. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.