By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

Multiline Textbox Problems

P: n/a
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
Share this Question
Share on Google+
13 Replies


P: n/a

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

P: n/a
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

P: n/a
thanks! I'll give that a shot

-PulsarSL

Jul 17 '05 #4

P: n/a
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

P: n/a
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

P: n/a
OHHH i think i need to do the str_replace before i write the file!
*lightbulb*

(dim lightbulb, but lightbulb)

Jul 17 '05 #7

P: n/a
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

P: n/a
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

P: n/a
Thanks, the n12br function was just what I was looking for.

-PulsarSL

Jul 17 '05 #10

P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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.