Jump to content

Archived

This topic is now archived and is closed to further replies.

gtridez

allowing only certain html tags using strip_tags

Recommended Posts

hey guys...
i need to allow only certain html tags when a user submits info in a form...
for example like only allow <b>, <img src".."> tags etc....
i'm familiar with strip_tags function...but any way to do what i want?

Share this post


Link to post
Share on other sites
[url=http://php.net/strip_tags]strip_tags[/url]() has an optional [i]allow tags[/i] argument. Use that.

Share this post


Link to post
Share on other sites
Sorry... ive never used it, your right... the manual is a little sprse there. You'll need to experement.

Share this post


Link to post
Share on other sites
As an example.... thsi code will let the <p> and </p> tags through.

[code=php:0]
<?php
  $a = "<p>this is a paragraph</p>";
  echo strip_tags($a,"<p>");
?>
[/code]

Share this post


Link to post
Share on other sites
And this lets <p> <a href=''> </a> and <p> through. Too easy.

[code=php:0]
<?php
  $a = "<p><a href=''>this is a paragrapgh</a></p>";
  echo strip_tags($a,"<p><a>");
?>
[/code]

EDIT: The [ / url] is meant to be a closing < / a >, thats the forum playin with it.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.