Forum Moderators: coopster

Message Too Old, No Replies

Remove some HTML tags when post a form

...and keep the tags in the allowance list

         

iProgram

6:48 am on Feb 17, 2005 (gmt 0)

10+ Year Member



A user writes an article using WYSIWYG HTML based editor and submit it to script.php(<form method="post" action="script.php">). I only want to keep the HTML tags which are in my allowance list and remove other tags from the post string. For example, here is the allowance list of tags:

<b>,<strong>,<p>, <ul>,<ol>,<li>, <a>

Before submission:

<strong>Hello, <a href="http://www.webmasterworld.com">WebmasterWorld</a><strong>.
<p align="center"><u>This is underline</u></p>
<script type="text/javascript">
alert('Hello, world');
</script>

After submission:

<strong>Hello, <a href="http://www.webmasterworld.com">WebmasterWorld</a><strong>.
<p align="center">This is underline</p>
alert('Hello, world');

That's, the <u> tag and <script> tag are removed. What is the most effective way to program with script.php?

yowza

7:10 am on Feb 17, 2005 (gmt 0)

10+ Year Member



i think you are looking for htmlspecialchars()

iProgram

8:09 am on Feb 17, 2005 (gmt 0)

10+ Year Member



htmlspecialchars "decodes" all HTML tags...
Drupal has the feature I am looking for but I could not find the related code...

coopster

12:10 pm on Feb 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



strip_tags [php.net]