Retaining Paragraphs and Spaces on my database

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Retaining Paragraphs and Spaces on my database

    Am currently designing a website for a company and the problem i gat is dat the form i created for the employees. saves all letters and alpabets on one line. the enter key does not space the information. i hope somebody understand me. for example if i type:
    hello pls kal

    mr john.

    it will save as hello pls kal mr john.. without the break line.


    pls help

    #2
    Use
    PHP Code:
    <textarea></textarea
    in place of
    PHP Code:
    <input type="text" /> 
    to get text like that

    Comment


      #3
      is there some filter which replaces line breaks before it adds the text to the database?
      something similar like:
      PHP Code:
      $str str_replace(array("\r\n""\n""\r"), ''$str); 
      if not, to show line breaks from database the same way in html you have to use a code like this:

      PHP Code:
      $str str_replace(array("\r\n""\n""\r"), '<br/>'$str); 
      Advertise your mobile site for FREE with AdTwirl

      Comment


        #4
        Originally posted by GumSlone View Post
        is there some filter which replaces line breaks before it adds the text to the database?
        something similar like:
        PHP Code:
        $str str_replace(array("\r\n""\n""\r"), ''$str); 
        if not, to show line breaks from database the same way in html you have to use a code like this:

        PHP Code:
        $str str_replace(array("\r\n""\n""\r"), '<br/>'$str); 
        just a question but wouldnt it be just as easy to do something like:

        PHP Code:
        $post nl2br($post);
        //
        //
        // 
        ??

        obviously $post var = their own post variable.

        as far as i know this does basically same thing. turning new lines into <br/> also.
        <?php
        include ('Ghost');
        if ($Post == true) {
        echo '

        sigpic
        alt='coding-talk.com!!' />';
        echo 'Sharing Is Caring!';
        } else {
        echo '

        alt='the username GHOST has been comprimised!' />';
        echo 'OMG SOMEBODY HELP ME!!';
        }
        ?>

        Comment


          #5
          Originally posted by Ghost View Post
          just a question but wouldnt it be just as easy to do something like:

          PHP Code:
          $post nl2br($post);
          //
          //
          // 
          ??

          obviously $post var = their own post variable.

          as far as i know this does basically same thing. turning new lines into <br/> also.
          yes, you are right your solution is better, this function was made specially to insert html line break into the text.
          Advertise your mobile site for FREE with AdTwirl

          Comment


            #6
            Originally posted by GumSlone View Post
            yes, you are right your solution is better, this function was made specially to insert html line break into the text.
            came up with a really nice solution to a flat file writing problem when using nl2br by adding it to a modded version of gumslones.

            using nl2br with txt files makes your text look like this inside the .txt file:

            this is<br />
            a trial message<br />
            that im producing to<br />
            use as an example.

            taking up 4 lines in the .txt file.
            (when trying to show to users it may look like its coming from 1 post, but it takes up a count of 4 posts in total)

            by modding gumslones code and using nl2br you can produce this inside the .txt file:

            this is<br/>a trial message<br/>that im producing to<br/>use as an example.

            ramming everything on 1 line and once again counting as 1 post total. so the display structure is always correct.

            heres what i did.

            PHP Code:
            /** Call Cleanse Function And <br /> All \r\n \r \n With nl2br */
            $Post nl2br(Cleanse($_POST['post']));
            /** Remove \r\n \r \n From <br /> Tags That nl2br Seem To Leave Behind. */
            $Post str_replace(array("<br />\r\n""<br />\n""<br />\r"), '<br/>'$Post); 
            //
            //
            // 
            Cleanse() is just a function i got for cleaning the posts also.
            Last edited by Ghost; 18.07.12, 22:25. Reason: EDITED WITH MORE INFO FOR BETTER EXAMPLE
            <?php
            include ('Ghost');
            if ($Post == true) {
            echo '

            sigpic
            alt='coding-talk.com!!' />';
            echo 'Sharing Is Caring!';
            } else {
            echo '

            alt='the username GHOST has been comprimised!' />';
            echo 'OMG SOMEBODY HELP ME!!';
            }
            ?>

            Comment


              #7
              You can use php end of line, it remains \n in markup but must be in double quotes. If you don't want it change those in single quotes. Btw i don't like nl2br because its white space, i like <br/> not <br />.

              PHP Code:
              str_replace(PHP_EOL"<br/>"$var); 
              or...

              PHP Code:
              $Post str_replace(PHP_EOL"<br/>"Cleanse($_POST['post'])); 
              Last edited by arnage; 20.07.12, 16:26.
              <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

              Comment


                #8
                Originally posted by arnage View Post
                You can use php end of line, it remains \n in markup but must be in double quotes. If you don't want it change those in single quotes. Btw i don't like nl2br because its white space, i like <br/> not <br />.

                PHP Code:
                str_replace(PHP_EOL"<br/>"$var); 
                or...

                PHP Code:
                $Post str_replace(PHP_EOL"<br/>"Cleanse($_POST['post'])); 
                thats why i added the:
                PHP Code:
                $Post str_replace(array("<br />\r\n""<br />\n""<br />\r"), '<br/>'$Post); 
                //
                //
                // 
                after using nl2br, not only does it remove the hidden new lines it leaves next to the <br />
                tags but it also turns <br /> into <br/> and cleans it up

                thanks for the input though
                <?php
                include ('Ghost');
                if ($Post == true) {
                echo '

                sigpic
                alt='coding-talk.com!!' />';
                echo 'Sharing Is Caring!';
                } else {
                echo '

                alt='the username GHOST has been comprimised!' />';
                echo 'OMG SOMEBODY HELP ME!!';
                }
                ?>

                Comment


                  #9
                  Np. Cool.
                  <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                  Comment

                  Working...
                  X