The woes of a PHP form submission

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin the Mac Addict

    #1

    The woes of a PHP form submission

    Good evening to the skilled Ladies and Gentlemen of the PHP world. I
    am fairly new to all of this but learning quickly. I have run in to a
    need to remove blank lines from a form submission after its sent back
    to the web server for processing by a PHP document.

    I have a textarea that users can paste lines of text in to and submit
    them for inclusion in to a database. Every aspect is working
    perfectly, except one. No matter what I try, I cannot get rid of
    simple blank lines from the form submission.

    $theLines = $HTTP_POST_VARS['userSubmitted'];

    This variable ($theLines) now contains the contents from the textarea.
    I have tried using ...

    $theLines = explode("\n", $theLines);

    and

    $theLines = explode("\r", $theLines);

    But all of the blank lines are still there. If anyone has some
    snippet that they would share, I would be very grateful.

    With great respect,

    Martin
  • hexkid

    #2
    Re: The woes of a PHP form submission

    Martin the Mac Addict wrote...
    [...][color=blue]
    > But all of the blank lines are still there. If anyone has some
    > snippet that they would share, I would be very grateful.[/color]

    <?php
    function remove_blank_li nes($txt) {
    str_replace("\r ", '', $txt); ## remove all "\r"s
    ## and convert all double enters (and triple ...) to one enter
    while (strpos($txt, "\n\n") !== false)
    $txt = str_replace("\n \n", "\n", $txt);
    return $txt;
    }
    ?>

    NOTE: this was typed into google without being checked.

    Comment

    • Nikolai Chuvakhin

      #3
      Re: The woes of a PHP form submission

      admin@minoguete ch.com (Martin the Mac Addict) wrote in message
      news:<e4ec48f2. 0309032035.fa32 93@posting.goog le.com>...[color=blue]
      >
      > I have a textarea that users can paste lines of text in to and submit
      > them for inclusion in to a database. Every aspect is working
      > perfectly, except one. No matter what I try, I cannot get rid of
      > simple blank lines from the form submission.[/color]

      This may be somehow related to the end-of-line character issue.
      End of line in DOS/Windows is a two-character sequence "\r\n",
      in Unix, a single character "\n", and in MacOS, a single character
      "\r". So if you want to strip end-of-line characters from a form
      submission, you should try something like this:

      $theLines = $HTTP_POST_VARS['userSubmitted'];
      $theLines = str_replace("\n ", '', $theLines);
      $theLines = str_replace("\r ", '', $theLines);

      Also, take a look at the script you use to render the submission.
      If you have something like this:

      <textarea>
      <?php
      echo $theLines;
      ?>

      </textarea>

      then the extra blank line actually comes from your HTML, not your
      PHP...

      Cheers,
      NC

      Comment

      Working...