Problems showing a newline within a textarea, once grabbed info from within a db

Status
Not open for further replies.

utomtear

Banned
Banned
33
2011
0
0
Basically i am having a little problem displaying a newline within a textarea. The contents of the text area are grabbed from a database, which have already previously converted all newlines to <br> tags, as i would like to use it within a html page. But i also want to offer a user the chance to edit this data via the use of a textarea. Now the problem is i would like the textarea to display the content in the same way it does on a html document, So i decided to replace <br> with \n once again, and then post the content within the <textarea>...</textarea> tags. But I seem to be getting "content with a \n instead of actually showing the newline itself". How would i overcome this??
 
3 comments
As deliteblogger said, be sure to use double quotes for your newline.

PHP:
<?php
$newline = "\n";
$text = 'Hello world';

echo '<textarea>';

echo $text . $newline; // -> Hello world + newline
echo $text . "\n"; // -> Hello world + newline
echo 'Hello World' . "\n"; // -> Hello world + newline

echo '</textarea>';
?>

Those three ways will work.
 
Last edited:
Status
Not open for further replies.
Back
Top