SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stripping HTML Tags

    Hi,

    I do know there's this function, http://www.php.net/manual/en/function.strip-tags.php

    But it seems to have some flaws. Like..it'lll strip even stuffs like: <bar

    from one of the comments posted by users.

    So how do yuo guys prevent users form entering html code? or how does vBulletin prevent HTML code from displaying? =)

    Thanks
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think vBulletin probably uses something like this :

    PHP Code:
    $str str_replace("&","&amp;",$str);
    $str str_replace("<","&lt;",$str);
    $str str_replace(">","&gt;",$str);
    $str str_replace("\n","<br>",$str); 
    Sean

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sean is on the right track:

    PHP Code:
    $str htmlspecialchars($str);
    $str nl2br($str); 
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  4. #4
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Sean and Kevin,

    I used :

    PHP Code:
    $comments htmlspecialchars("$comments"ENT_QUOTES);
    $comments nl2br($comments); 

    =)))
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •