Selective HTML tags striping with Smarty

Discussion in 'PHP' started by ahmadfarhan, Jun 30, 2008.

  1. #1
    How do I do selective tag stripping with Smarty.

    What I mean is that I want o strip the HTML tags. But not all. I want to allow some. For example. <b>,<p>, <a> etc.. but not allow some.. for example <script>,<iframe> etc..

    is this possible with smarty? or do I need to process this myself before passing the output to smarty.
     
    ahmadfarhan, Jun 30, 2008 IP
  2. AliasXNeo

    AliasXNeo Banned

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I believe it would be somewhat possible with Smarty using some basic library commands (equivalent to PHP's str_replace or preg_replace) but honestly it would be the last thing I would trust security wise. I would work on a class that strips the information in a more secure way (plenty of tutorials on this). Also a simple Google search will result in several pre-written classes that handle this process.

    Optionally you can just use the PHP strip_tags() function which takes in the content and exceptions not to strip.
     
    AliasXNeo, Jun 30, 2008 IP
  3. ahmadfarhan

    ahmadfarhan Peon

    Messages:
    211
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yeah.. i used "html purified" with some of my other projects.. just thought that maybe I can let smarty do it this time.
     
    ahmadfarhan, Jun 30, 2008 IP
  4. AliasXNeo

    AliasXNeo Banned

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well like I said, it's probably possible since Smarty supports RegEx, but in my opinion not worth what space it might save in your actual PHP coding. Unless there's any particular reason why Smarty needs to handle it, I honestly see no point considering all the negatives it creates (poor security, hard to debug, etc.). You might just want to make your own Smarty module (assuming there isn't already one already out there) if you honestly want to stick with it. You can even port HTML Purified in there.
     
    AliasXNeo, Jun 30, 2008 IP