Multiline Textbox Problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • IWP506@gmail.com

    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

  • Tom Thackrey

    #2
    Re: Multiline Textbox Problems


    On 18-May-2005, IWP506@gmail.co m wrote:
    [color=blue]
    > 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.[/color]

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

    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • Bzdziul

      #3
      Re: Multiline Textbox Problems

      U¿ytkownik "Tom Thackrey" <use.signature@ nospam.com> napisa³ w wiadomo¶ci
      news:EePie.1866 4$J12.14413@new ssvr14.news.pro digy.com...[color=blue]
      > The problem is the browser treats newlines as white space. Change \n to[/color]
      <br>[color=blue]
      > ( str_replace("\n ",'<br>',$t xt) ) before you echo it to the browser.[/color]
      there is a function nl2br() ;-)
      also you can print tag <pre> before $txt

      Comment

      • IWP506@gmail.com

        #4
        Re: Multiline Textbox Problems

        thanks! I'll give that a shot

        -PulsarSL

        Comment

        • Malcolm Dew-Jones

          #5
          Re: Multiline Textbox Problems

          IWP506@gmail.co m 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.

          Comment

          • IWP506@gmail.com

            #6
            Re: Multiline Textbox Problems

            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=$mynot es . $x;
            }
            str_replace("\n ",'<br>',$mynot es);
            echo $mynotes;
            fclose($f);
            ?>

            Thanks
            PulsarSL

            Comment

            • IWP506@gmail.com

              #7
              Re: Multiline Textbox Problems

              OHHH i think i need to do the str_replace before i write the file!


              *lightbulb*

              (dim lightbulb, but lightbulb)

              Comment

              • thehuby

                #8
                Re: Multiline Textbox Problems

                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/

                Comment

                • thehuby

                  #9
                  Re: Multiline Textbox Problems

                  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/

                  Comment

                  • IWP506@gmail.com

                    #10
                    Re: Multiline Textbox Problems

                    Thanks, the n12br function was just what I was looking for.

                    -PulsarSL

                    Comment

                    • manish

                      #11
                      Re: Multiline Textbox Problems

                      "thehuby" <rick.huby@e-connected.com> wrote in message news:<111657592 7.241312.25240@ f14g2000cwb.goo glegroups.com>. ..[color=blue]
                      > You could also try using myStr = nl2br(myStr) - this is PHP's built in
                      > function for doing what you are describing.[/color]

                      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.

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Multiline Textbox Problems

                        manish wrote:[color=blue]
                        > "thehuby" <rick.huby@e-connected.com> wrote in message news:<111657592 7.241312.25240@ f14g2000cwb.goo glegroups.com>. ..
                        >[color=green]
                        >>You could also try using myStr = nl2br(myStr) - this is PHP's built in
                        >>function for doing what you are describing.[/color]
                        >
                        >
                        > 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.[/color]

                        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.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • Tony

                          #13
                          Re: Multiline Textbox Problems

                          "manish" <yehaimanish@gm ail.com> wrote in message
                          news:1885add9.0 505260145.49678 9f9@posting.goo gle.com...[color=blue]
                          > "thehuby" <rick.huby@e-connected.com> wrote in message
                          > news:<111657592 7.241312.25240@ f14g2000cwb.goo glegroups.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.[/color]

                          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


                          Comment

                          • manish

                            #14
                            Re: Multiline Textbox Problems

                            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($descript ion);

                            Thanks.


                            Jerry Stuckle <jstucklex@attg lobal.net> wrote in message news:<2bmdnWFj7 cf3JAjfRVn-gQ@comcast.com> ...[color=blue]
                            > manish wrote:[color=green]
                            > > "thehuby" <rick.huby@e-connected.com> wrote in message news:<111657592 7.241312.25240@ f14g2000cwb.goo glegroups.com>. ..
                            > >[color=darkred]
                            > >>You could also try using myStr = nl2br(myStr) - this is PHP's built in
                            > >>function for doing what you are describing.[/color]
                            > >
                            > >
                            > > 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.[/color]
                            >
                            > 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;[/color]

                            Comment

                            Working...