SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to not allow HTML tags

    Hey, I am making a news article comment script and I want to code it so that when somebody puts html tags in the comment, it won't execute the html but just display the tags.

    In the database I have the comment field set up as
    Type: Text
    Null: Yes

    and in the script I just connect to the database and then echo the variable.

    How can I make it so that when echoing the variable it won't execute the html?

    Thanks to anyone that helps!

  2. #2
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a pretty easy thing to do.

    Code:
    $string = eregi_replace("<", "&lt;", $string);
    $string = eregi_replace(">", "&gt;", $string);
    That will just replace the brackets < and > with the HTML codes for the brackets. Making the code plain text on the page.

  3. #3
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or

    PHP Code:
    $find = array('<','>');
    $replace = array('&lt;','&gt;');

    $string str_replace($find,$replace,$string); 

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also see htmlentities

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Ontario, Canada
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or htmlspecialchars(). All should work properly.
    Brock Ferguson
    Lead Developer, Caribou CMS
    A Subscription/Membership CMS and Ecommerce Platform - FREE Trial


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
  •