Sam Granger Posted October 25, 2007 Share Posted October 25, 2007 I have a question. At the moment, with my code I can post text into mysql. in my textarea however, if I type the following: Hello. Text goes here. And a seperate paragraph here also! I get the following when I view the text in my php page (simple query): Hello. Text goes here. And a seperate paragraph here also! As you can see, <enter> is changed into a space. However I want each <enter> equal a space. The MySQL looks like this: Hello.\r\n\r\nText goes here.\r\n\r\nAnd a seperate paragraph here also! Now, I assume I need to do something with str_replace. But what does \r mean and what does \n mean? Quote Link to comment https://forums.phpfreaks.com/topic/74733-solved-what-does-r-mean-and-what-does-n-mean/ Share on other sites More sharing options...
kenrbnsn Posted October 25, 2007 Share Posted October 25, 2007 Use the function nl2br() on your output. The characters "\r\n" represent the newline character. "\r" is a carriage return and "\n" is a line-feed. On UNIX systems "\n" is the newline character. On Macs it is "\r". The nl2br() function will put a "<br>" tag in front of each newline character. Ken Quote Link to comment https://forums.phpfreaks.com/topic/74733-solved-what-does-r-mean-and-what-does-n-mean/#findComment-377786 Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 \r = CR (carriage return) \n = LF (line feed) they are used for splitting into lines.. but to start a new line depends on the system.. Windows = \r\n unix = \n Mac = \r Now. if you view source your see the line are broken up.. but you need to convert this to html.. so to do this use nl2br() ie <?php $str ="Hello.\r\n\r\nText goes here.\r\n\r\nAnd a seperate paragraph here also!"; echo nl2br($str); ?> EDIT: Ahh .. too slow Quote Link to comment https://forums.phpfreaks.com/topic/74733-solved-what-does-r-mean-and-what-does-n-mean/#findComment-377789 Share on other sites More sharing options...
Sam Granger Posted October 25, 2007 Author Share Posted October 25, 2007 Cool guys, thanks both of you! Quote Link to comment https://forums.phpfreaks.com/topic/74733-solved-what-does-r-mean-and-what-does-n-mean/#findComment-377793 Share on other sites More sharing options...
Zane Posted October 25, 2007 Share Posted October 25, 2007 \r is a carriage return and \n is newline character you really only need one or the other, but most people use both of them together as one \r\n to make their scripts work with as many browsers/applications as they can EDIT damn...everyone beat me Quote Link to comment https://forums.phpfreaks.com/topic/74733-solved-what-does-r-mean-and-what-does-n-mean/#findComment-377794 Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 Can you click solved please.. (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/74733-solved-what-does-r-mean-and-what-does-n-mean/#findComment-377799 Share on other sites More sharing options...
Sam Granger Posted October 25, 2007 Author Share Posted October 25, 2007 Yes, just tried it out and it works like a dream! Quote Link to comment https://forums.phpfreaks.com/topic/74733-solved-what-does-r-mean-and-what-does-n-mean/#findComment-377800 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.