textbox into MYSQL with text formatting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrhitokiri
    New Member
    • Apr 2008
    • 35

    textbox into MYSQL with text formatting

    hi again! this is another problem i encountered while doing my projects. you see, i have this textfield, and i would like to save what's in that textfield into the sql db with the formatting, like indentations. i already resolved the problem with newlines, but i guess this is the next one i need solved. thanks for you help again!

    bu the way, here's the codes i placed in my project
    [PHP]
    $sys_app = $_POST['sys_app'];
    $sys_app = nl2br($sys_app) ; // for line breaks
    [/PHP]

    [html]
    <textarea name="sys_app" cols=70 rows=6></textarea>
    [/html]
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    I don't understand what the problem is? You want to indent the text box input before you put it in MySQL???

    Comment

    • jrhitokiri
      New Member
      • Apr 2008
      • 35

      #3
      Originally posted by TheServant
      I don't understand what the problem is? You want to indent the text box input before you put it in MySQL???
      no.. it's some kind of forum, you see. When the user inputs an indentation, the indentation is also stored in the DB as is the line feeds.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        What does the user put in for his indentation? Probably blanks or a TAB char. You can translate the blank chars into &nbsp; literals and store that in the db.

        Ronald

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by ronverdonk
          What does the user put in for his indentation? Probably blanks or a TAB char. You can translate the blank chars into &nbsp; literals and store that in the db.

          Ronald
          Mhm, using that logic you could create a function:
          [php]
          $_tab = "spaced\tout\tm aaaaan";
          function tab2ind($_strin g)
          {
          $_string = str_replace("\t ", "&nbsp;&nbsp;&n bsp;&nbsp;", $_string);
          return $_string;
          }
          echo tab2ind($_tab);
          [/php]
          :)

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Hi.

            Wrapping formatted text in <pre></pre> tags will show it with the formatting.

            For example:
            [code=html]
            Normal:
            <div>
            Indented line
            Line 2 Lots of spaces
            </div>
            <br /><br />
            Pre:
            <pre>
            Indented line
            Line 2 Lots of spaces
            </pre>
            [/code]
            Will result in
            Code:
            Normal:
             Indented line Line 2 Lots of spaces
            
            Pre:
                Indented line
                Line 2        Lots of spaces

            Comment

            • jrhitokiri
              New Member
              • Apr 2008
              • 35

              #7
              Originally posted by Atli
              Hi.

              Wrapping formatted text in <pre></pre> tags will show it with the formatting.

              For example:
              [code=html]
              Normal:
              <div>
              Indented line
              Line 2 Lots of spaces
              </div>
              <br /><br />
              Pre:
              <pre>
              Indented line
              Line 2 Lots of spaces
              </pre>
              [/code]
              Will result in
              Code:
              Normal:
               Indented line Line 2 Lots of spaces
              
              Pre:
                  Indented line
                  Line 2        Lots of spaces

              wow! this does works! thanks for the help!:D

              cheers!:D

              Comment

              Working...