Results 1 to 3 of 3

Thread: [RESOLVED] upon $_POST keep spaces and formatting

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    119

    Resolved [RESOLVED] upon $_POST keep spaces and formatting

    Hello, I'm after a little tip. I am making a pm system for my website, the problem is the majority of people on my site wont know html. In the text area when a user spaces out there message (paragraph) with the enter key. I want this to stay the same. When the person gets this message, the space is gone. Any idea's. Like if I send this.

    Hello friend,

    how are you
    The person will see this message like this.

    Hello friend,how are you
    I want to keep the spaces
    Last edited by Shadows; Jul 13th, 2005 at 06:48 PM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: upon $_POST keep spaces and formatting

    When you output the text use the nl2br() function. This will convert all new lines to HTML line breaks. If you want to preserve spaces, you should use <pre> tags.
    PHP Code:
    ?>
    <pre>
    <?php echo($text); ?>
    </pre>
    You can also use the str_replace() function to find all spaces and replace them with a non breaking soace '&nbsp;':
    PHP Code:
    $text str_replace(' ''&vbsp;'$text); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    119

    Re: upon $_POST keep spaces and formatting

    Quote Originally Posted by visualAd
    When you output the text use the nl2br() function. This will convert all new lines to HTML line breaks. If you want to preserve spaces, you should use <pre> tags.
    PHP Code:
    ?>
    <pre>
    <?php echo($text); ?>
    </pre>
    You can also use the str_replace() function to find all spaces and replace them with a non breaking soace '&nbsp;':
    PHP Code:
    $text str_replace(' ''&vbsp;'$text); 
    absolutely fantasic, thank you mate, my script works perfectly from your tip, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width