Jump to content

Recommended Posts

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?

 

 

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

\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

\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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.