SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member Pusted's Avatar
    Join Date
    Oct 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post How to remove <br />

    Hi there:
    I have a comment script and when people write something in goes to MySql database and after that when I display that text I have "<br />" on the plase where the user have pressed "enter".
    I'm using "addslashes(htmlspecialchars($comment))" to ad the comment to database.

    Any sugestions?


    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Are you sure you aren't using nl2br as well?

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should use rawurlencode($comment) at insertion and when you want to display data then use rawurldecode($comment)

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    url encoding and decoding isnt neccesary nor is it desirable here.

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It could be the output code. What is the code you use, from getting it out of the database to outputting it to the browser?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The correct way of doing this should be:
    nl2br(htmlspecialchars($s));

  7. #7
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pusted View Post
    Hi there:
    I have a comment script and when people write something in goes to MySql database and after that when I display that text I have "<br />" on the plase where the user have pressed "enter".
    I'm using "addslashes(htmlspecialchars($comment))" to ad the comment to database.

    Any sugestions?


    Thanks
    That's because htmlspecialchars($comment) changes all

    Code:
    <br />
    in the comment to

    Code:
    &lt;br /&gt;
    Solution to this is:

    You must use htmlspecialchars() before you change all double newlines to <br /> tags. If you first change newlines to <br /> tags, htmlspecialchars() will convert < and > to HTML entities.

    So something like this:

    PHP Code:
    $comment htmlspecialchars($comment);
    $comment nl2br($comment); 
    Edited...


Bookmarks

Posting Permissions

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