[SOLVED] how to get the text to stay the same?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    [SOLVED] how to get the text to stay the same?

    Hi

    For my first php project i designed a simple CMS.

    When I write text in my text field and submit and then view it later on the display page the text is not keeping it spaces, line breaks etc.

    What can i add to the script to dsiplay it as the same as i wrote it?

    Kind Regards
    Louwrens
  • khalidbaloch
    New Member
    • Oct 2006
    • 61

    #2
    i think this is what you need
    Code:
    <?php
    if($submit =="submit") {echo " did you typed <b>$text</b> ?"; 
    }
    else { echo "<form action='' method=post enctype=multipart/form-data><font color=blue size=4>type text here </font>
    <input type=text size=20 name=text />
    <input type=submit name=submit value=submit /></form>";
    }?>
    is this sufficent ?

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      When you want to display the entered line breaks as breaks in your HTML, you'll have to convert the 'normal' newline characters to HTML break statements, by using the nl2br() command. As in

      [php]echo nl2br($_POST['text']);[/php]
      HTML compresses muliti-spaces into one space when displayed. If you want to show the same number of spaces, you must translate each space to a non-breaking-space char &nbsp; before you display it.
      So, with the above in mind, your display code could look like:

      [php]echo nl2br(str_repla ce(' ', '&nbsp;', $_POST['text']));[/php]

      Ronald :cool:

      Comment

      • webandwe
        New Member
        • Oct 2006
        • 142

        #4
        thank you.

        Comment

        Working...