Hi all
I made a simple php page with a form with a text area and a submit button. Clicking the submit button writes the content of the text area into an html page.
It is like a very very basic blog, and I'm glad I got so far.
The next thing I need to figure out is:
when I write in the text area, and press the return key to go to the next line, I want this to translate into a <br>, so that the line breaks will be reproduced when the content of the text area is written into the html page.
(oh, and I need something that will work in both Mac and PC).
How can I do that?
Thanks for your help
return key should create a <br> in text area
Moderator: General Moderators
-
sebnewyork
- Forum Commoner
- Posts: 43
- Joined: Wed Mar 17, 2004 10:20 pm
-
sebnewyork
- Forum Commoner
- Posts: 43
- Joined: Wed Mar 17, 2004 10:20 pm
Thanks, I did a google search and found this
nl2br()
as well as other ways to do it.
I must be missing something, because nothing worked so far:
I've tried:
I've tried:
I've tried also with \r\n instead of \n
In all cases the text does get written in "text.htm", but no line breaks.
What am I missing?
nl2br()
as well as other ways to do it.
I must be missing something, because nothing worked so far:
I've tried:
Code: Select all
<?php
if (isset ($_POST['submit'])) {
if (!empty ($_POST['content'])) {
if ($fp = fopen ("text.htm", 'a')) {
fwrite ($fp, nl2br("$content"));
fclose ($fp);
header ('location: text.htm');
}
}
}
?>Code: Select all
<?php
if (isset ($_POST['submit'])) {
if (!empty ($_POST['content'])) {
if ($fp = fopen ("text.htm", 'a')) {
$data = str_replace("<br>", "\n", $content);
fwrite ($fp, "$data");
fclose ($fp);
header ('location: text.htm');
}
}
}
?>In all cases the text does get written in "text.htm", but no line breaks.
What am I missing?
-
sebnewyork
- Forum Commoner
- Posts: 43
- Joined: Wed Mar 17, 2004 10:20 pm