Web Analytics Made Easy -
StatCounter htmlentities line break - CodingForum

Announcement

Collapse
No announcement yet.

htmlentities line break

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

  • htmlentities line break

    Im using htmlentities and it prints all the text on one line.....like if i type

    this
    is
    my
    text

    inside the textbox, when it prints it to the page it comes out like:

    this is my text


    what do i do so it wont do that
    ~Designer's Toolz~

  • #2
    I guess you could use

    PHP Code:
    $str str_replace("&lt;br /&gt;","<br />",$str); 

    Comment


    • #3
      that doesnt work
      ~Designer's Toolz~

      Comment


      • #4
        PHP Code:
        print nl2br($string); 

        Comment


        • #5
          unless you need something like this:
          PHP Code:
          $string str_replace("&lt;br /&gt;","<br/>",htmlentities(nl2br($string))); 

          Comment


          • #6
            .
            PHP Code:
             $string str_replace("&lt;br /&gt;","<br/>",htmlentities(nl2br($string))); 

            works like a charm. thanks.
            ~Designer's Toolz~

            Comment


            • #7
              actually after more testing it doesnt work all the wayit does this:

              prints:

              &lt;html&gt;

              instead of:

              <html>
              ~Designer's Toolz~

              Comment


              • #8
                Well the ways me and celtboy have shown you will work. So obviously you've got to show us the code you're using. There's no point in us spending time showing you code when you're already using it and such

                Comment


                • #9
                  that's because
                  PHP Code:
                  htmlentities("<html>"); 
                  returns &lt;html&gt;

                  that's what htmlentities does. If you need to undo that,

                  PHP Code:
                  $string str_replace("&gt;",">",str_replace("&gt;",">",htmlentities(nl2br($string)))); 
                  i have no clue if that will work...lol...:

                  Comment


                  • #10
                    Well the ways me and celtboy have shown you will work. So obviously you've got to show us the code you're using. There's no point in us spending time showing you code when you're already using it and such


                    yeah...works until you post a code that has <br /> in it which is uh..a major problem



                    which would be:


                    PHP Code:
                     $string str_replace("&lt;br /&gt;","<br/>",htmlentities(nl2br($string))); 
                    ~Designer's Toolz~

                    Comment


                    • #11
                      If you're interested, take a look at this, too.
                      http://php.net/get_html_translation_table
                      www.united-scripts.com
                      www.codebattles.org

                      Comment

                      Working...
                      X