470,848 Members | 1,111 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

new lines in form

well, it is time for some fine tuning of my application, after adding
that banner script for which I needed percentage solution, I would like
to fix my forum scripts...
when someone write some text in form's textarea and then
enter
new line (btw, is that \r or \n or combination?) I'm not "getting" that
new line but space. what can I do to "recieve" and store (in mysql db)
text with newlines instead of spaces. and, even better, to replace that
newline with </p>\n<p>...

tnx again

--
Ja NE
http://fotozine.org/?omen=janimir
--
Oct 25 '05 #1
3 1553
Ja NE <hi****@mail.zz> wrote:

....ok.
have it ;-))

$tekst = preg_replace("/\r\n/", "\n", $tekst);
$tekst = preg_replace("/\n/", "</p>\n<p>", $tekst);

thank you "manual" ;-)
well, it is time for some fine tuning of my application, after adding
that banner script for which I needed percentage solution, I would like
to fix my forum scripts...
when someone write some text in form's textarea and then
enter
new line (btw, is that \r or \n or combination?) I'm not "getting" that
new line but space. what can I do to "recieve" and store (in mysql db)
text with newlines instead of spaces. and, even better, to replace that
newline with </p>\n<p>...

tnx again

--
Ja NE
http://fotozine.org/?omen=janimir
--
Oct 25 '05 #2
IWT
Ja NE wrote:
when someone write some text in form's textarea and then
enter
new line (btw, is that \r or \n or combination?) I'm not "getting" that
new line but space. what can I do to "recieve" and store (in mysql db)
text with newlines instead of spaces. and, even better, to replace that
newline with </p>\n<p>...

I've just done something very similar:

$description=$_POST['textarea'];

$description = strip_tags($description); // Remove any HTML tags
$description = "<p>".$description; // Add <p> to start
$description = str_replace("\r\n","</p><p>", $description); // Replace
new lines with paragraph

if(substr($description,-3)=="<p>") // Remove last <p> from description
$description = substr($description,0,-3);

Oct 25 '05 #3
Ja NE wrote:
well, it is time for some fine tuning of my application, after adding
that banner script for which I needed percentage solution, I would like
to fix my forum scripts...
when someone write some text in form's textarea and then
enter
new line (btw, is that \r or \n or combination?) I'm not "getting" that
new line but space. what can I do to "recieve" and store (in mysql db)
text with newlines instead of spaces. and, even better, to replace that
newline with </p>\n<p>...

tnx again


Jane,

That's the way HTML works - if you look at the page source and you'll
see the newlines in there. But processing the HTML gets rid of them.

You need to use something like PHP's nl2br() function to convert newline
characters to html breaks.

It can get very confusing when a newline "isn't" a newline!
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 25 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Katrin Limp?ck | last post: by
3 posts views Thread by Rolf | last post: by
5 posts views Thread by Brian | last post: by
23 posts views Thread by Paul Mars | last post: by
9 posts views Thread by davetelling | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
4 posts views Thread by =?Utf-8?B?R2lkaQ==?= | last post: by
7 posts views Thread by Gustaf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.