how to insert carriage return
Moderator: General Moderators
how to insert carriage return
I have a text box, and I would like to add in a carriage return in the box when inputting data through a php script, so that when the information is seen on the website, it would be formatted thus. Can anyone point me in the direction of a script that would help to make this possible?
$text = "line one\r\nline two\r\nline three\r\n";
<textarea><?php echo $text; ?></textarea>
carriage return is accomplished by using "\r" (must be inside double quotes)
new line is accomplished by using "\n" (must be inside double quotes)
macs use \r for a "new line", *nix use \n, win uses \r\n
you should use \r\n, that way you know its always gonna work
<textarea><?php echo $text; ?></textarea>
carriage return is accomplished by using "\r" (must be inside double quotes)
new line is accomplished by using "\n" (must be inside double quotes)
macs use \r for a "new line", *nix use \n, win uses \r\n
you should use \r\n, that way you know its always gonna work
yes, but ONLY if you have have php echo it
when php encounters a \r inside of a double quotted string, it will change \r into a carriage return
try the little code bit i posted
again, id recomend using \r\n, because if the browser doesnt interpret a lone \r or \n correctly, visually to the user it will look like its all on 1 line.
if you use \r\n then all browsers will definately render it correct.
theres prob few browsers that wouldnt interpret a lone \r or \n correctly, but i dont see any real drabacks to being safe about it.
when php encounters a \r inside of a double quotted string, it will change \r into a carriage return
try the little code bit i posted
again, id recomend using \r\n, because if the browser doesnt interpret a lone \r or \n correctly, visually to the user it will look like its all on 1 line.
if you use \r\n then all browsers will definately render it correct.
theres prob few browsers that wouldnt interpret a lone \r or \n correctly, but i dont see any real drabacks to being safe about it.
kendall wrote:Arent carriage return invisibly inserted in wrapped text areas?
KEndall
depending on the browser, and if the html has specified a certain wrap="virtual" attribute or whatever, yes. (default most browsers definately insert temporary, line breaks)
but when they submit the form, the virtual line breaks wont be sent. but depending on the wrap="" it could be. theres diff ways you can choose as the html designer.
i hope i have confused you