Jump to content


Photo

allowing only certain html tags using strip_tags


  • Please log in to reply
6 replies to this topic

#1 gtridez

gtridez
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 25 July 2006 - 04:24 AM

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?

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 July 2006 - 04:27 AM

strip_tags() has an optional allow tags argument. Use that.

#3 gtridez

gtridez
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 25 July 2006 - 04:34 AM

thanx...anywhere i can get a little more info on that?

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 July 2006 - 04:37 AM

Sorry... ive never used it, your right... the manual is a little sprse there. You'll need to experement.

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 July 2006 - 04:39 AM

As an example.... thsi code will let the <p> and </p> tags through.

<?php
  $a = "<p>this is a paragraph</p>";
  echo strip_tags($a,"<p>");
?>


#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 July 2006 - 04:41 AM

And this lets <p> <a href=''> </a> and <p> through. Too easy.

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

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

#7 gtridez

gtridez
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 25 July 2006 - 04:51 AM

hey thanx alot...i think that should work






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users