472,131 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,131 software developers and data experts.

Multiline Textbox Problems

Hey all, I'm having some trouble. On a page, I've got a multiline text
box. When I enter :

a
b
c
d

and hit submit (sending to my post.php page) and from post.php, echo
$_POST["info"] if shows up as a b c d. No carrige returns show. My
questions is... how can I do this? I know it's possible because I've
seen demonstrations, but can't seem to figure out how to do it.

Thanks,
IWP506

Jul 17 '05 #1
13 5995

On 18-May-2005, IW****@gmail.com wrote:
Hey all, I'm having some trouble. On a page, I've got a multiline text
box. When I enter :

a
b
c
d

and hit submit (sending to my post.php page) and from post.php, echo
$_POST["info"] if shows up as a b c d. No carrige returns show. My
questions is... how can I do this? I know it's possible because I've
seen demonstrations, but can't seem to figure out how to do it.


The problem is the browser treats newlines as white space. Change \n to <br>
( str_replace("\n",'<br>',$txt) ) before you echo it to the browser.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2
Użytkownik "Tom Thackrey" <us***********@nospam.com> napisał w wiadomo¶ci
news:Ee*******************@newssvr14.news.prodigy. com...
The problem is the browser treats newlines as white space. Change \n to <br> ( str_replace("\n",'<br>',$txt) ) before you echo it to the browser.

there is a function nl2br() ;-)
also you can print tag <pre> before $txt

Jul 17 '05 #3
thanks! I'll give that a shot

-PulsarSL

Jul 17 '05 #4
IW****@gmail.com wrote:
: Hey all, I'm having some trouble. On a page, I've got a multiline text
: box. When I enter :

: a
: b
: c
: d

: and hit submit (sending to my post.php page) and from post.php, echo
: $_POST["info"] if shows up as a b c d. No carrige returns show. My
: questions is... how can I do this? I know it's possible because I've
: seen demonstrations, but can't seem to figure out how to do it.

One issue is that the HTML in the form makes a difference to what you get
back.

The edit field can wrap the lines to display them so they look like
separate lines even if they are still on the same "physical" line (like
what a word processor does).

So, look up the various attributes for the HTML FORM input element you are
using, and try the various options to see what diference they make.
--

This space not for rent.
Jul 17 '05 #5
Hm... doesn't seem to be working. here's my code, It echos nothing.

-----

<html>
<body>
<?php
$mynotes="";
if (!($f=fopen("./posts/" . $_POST["password"] . ".txt" ,"r")))
exit("Unable to open file.");
while (!feof($f))
{
$x=fgetc($f);
//echo $x;
$mynotes=$mynotes . $x;
}
str_replace("\n",'<br>',$mynotes);
echo $mynotes;
fclose($f);
?>

Thanks
PulsarSL

Jul 17 '05 #6
OHHH i think i need to do the str_replace before i write the file!
*lightbulb*

(dim lightbulb, but lightbulb)

Jul 17 '05 #7
You could also try using myStr = nl2br(myStr) - this is PHP's built in
function for doing what you are describing.

--
Rick - www.e-connected.com/functional/

Jul 17 '05 #8
You could also try using myStr = nl2br(myStr) - this is PHP's built in
function for doing what you are describing.

--
Rick - www.e-connected.com/

Jul 17 '05 #9
Thanks, the n12br function was just what I was looking for.

-PulsarSL

Jul 17 '05 #10
"thehuby" <ri*******@e-connected.com> wrote in message news:<11*********************@f14g2000cwb.googlegr oups.com>...
You could also try using myStr = nl2br(myStr) - this is PHP's built in
function for doing what you are describing.


I am using the textarea to enter the data from the form into the
database. In the textarea, the data was entered as (new line and
spaces)

Welcome
My web site

Hello everyone,
In this site you will find some php code.
The data was saved in the database field exactly the same.

Now in the edit form, the data was again displayed exactly the same in
the textarea exactly the same. But when the data was echoed in the php
code, the data was displyed without the spaces that was inserted. The
variabled that was echoed in both textare (at edit time) and at
displaying come from the database.
Welcome
My web site

Hello everyone,
In this site you will find some php code.

Now can anyone help with the problem, so that spaces are also
displayed.
Jul 17 '05 #11
manish wrote:
"thehuby" <ri*******@e-connected.com> wrote in message news:<11*********************@f14g2000cwb.googlegr oups.com>...
You could also try using myStr = nl2br(myStr) - this is PHP's built in
function for doing what you are describing.

I am using the textarea to enter the data from the form into the
database. In the textarea, the data was entered as (new line and
spaces)

Welcome
My web site

Hello everyone,
In this site you will find some php code.
The data was saved in the database field exactly the same.

Now in the edit form, the data was again displayed exactly the same in
the textarea exactly the same. But when the data was echoed in the php
code, the data was displyed without the spaces that was inserted. The
variabled that was echoed in both textare (at edit time) and at
displaying come from the database.
Welcome
My web site

Hello everyone,
In this site you will find some php code.

Now can anyone help with the problem, so that spaces are also
displayed.


They're there - look at your source. The HTML parser will remove out
extra white space.

You can surround the output with <pare></pre> or convert the extra
spaces to &nbsp;

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #12
"manish" <ye*********@gmail.com> wrote in message
news:18**************************@posting.google.c om...
"thehuby" <ri*******@e-connected.com> wrote in message
news:<11*********************@f14g2000cwb.googlegr oups.com>...
Now in the edit form, the data was again displayed exactly the same in
the textarea exactly the same. But when the data was echoed in the php
code, the data was displyed without the spaces that was inserted. The
variabled that was echoed in both textare (at edit time) and at
displaying come from the database.
Welcome
My web site

Hello everyone,
In this site you will find some php code.

Now can anyone help with the problem, so that spaces are also
displayed.


You really have basically two choices, far as I can tell - the problem is
with HTML, not PHP.

Either replace all spaces in the field with '&nbsp;' or wrap the entire
output in <pre></pre> tags
Jul 17 '05 #13
Having <pre></pre> tag doen't give the same number of spaces that was inserted.

Howerever using str_replace works prefectly

$description = str_replace(" ", "&nbsp;", $description);
echo nl2br($description);

Thanks.
Jerry Stuckle <js*******@attglobal.net> wrote in message news:<2b********************@comcast.com>...
manish wrote:
"thehuby" <ri*******@e-connected.com> wrote in message news:<11*********************@f14g2000cwb.googlegr oups.com>...
You could also try using myStr = nl2br(myStr) - this is PHP's built in
function for doing what you are describing.

I am using the textarea to enter the data from the form into the
database. In the textarea, the data was entered as (new line and
spaces)

Welcome
My web site

Hello everyone,
In this site you will find some php code.
The data was saved in the database field exactly the same.

Now in the edit form, the data was again displayed exactly the same in
the textarea exactly the same. But when the data was echoed in the php
code, the data was displyed without the spaces that was inserted. The
variabled that was echoed in both textare (at edit time) and at
displaying come from the database.
Welcome
My web site

Hello everyone,
In this site you will find some php code.

Now can anyone help with the problem, so that spaces are also
displayed.


They're there - look at your source. The HTML parser will remove out
extra white space.

You can surround the output with <pare></pre> or convert the extra
spaces to &nbsp;

Jul 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Michael C | last post: by
7 posts views Thread by Joel Finkel | last post: by
2 posts views Thread by Enzo Marinelli | last post: by
4 posts views Thread by =?Utf-8?B?R2lkaQ==?= | last post: by
2 posts views Thread by Nathan Sokalski | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.