Pub Pixel Avatar Image

Learn How To Strip HTML & PHP Tags From User Submitted Data Using PHP

Published:

Rate Article (Sign in and be the first to rate this article.)

Article Details

Views: 1850

First Published:

Word Count: 318

Edition: 1

If you ever need to strip out the HTML or PHP tags from data, PHP gives you a way to do this via the strip_tags() function, which was introduced to us in PHP version 3.0.8. In PHP 5.0.0 and up the strip_tags() function is now binary safe.

The strip_tags() function strips a string from HTML and PHP tags and even XML tags. The strip_tags() function has two parameters, which are listed below:

string

The first parameter is the input string which is a required string that you want stripped of HTML and PHP tags.

Here is how to code the required string parameter for the strip_tags() function.


<?php

$required_string = '<p>Data and text to be <strong>stripped.</strong></p>';  
echo strip_tags($required_string);

?>

allowable_tags

The second parameter specifies the allowable tags that should not be stripped. In PHP version 4.3.0 and up HTML comments are always stripped. You should also know that when the HTML comments and PHP tags are stripped they cannot be changed with the allowable_tags parameter because its hard coded into the strip_tags() function.

Here is how to code the second parameter allowable_tags for the strip_tags() function.


<?php

$required_string = '<p>Data and text to be <strong>stripped.</strong></p>';  
echo strip_tags($required_string, '<p><strong>');

?>

Here is how to code the strip_tags() function and its required string parameter.


<?php

$required_string = '<p>Data and text to be <strong>stripped.</strong></p>';  
echo strip_tags($required_string);

?>

If you need more information about the strip_tags() function check out the PHP manual at http://www.php.net/manual/en/function.strip-tags.php

Article Tags

Tag Article (Sign in if you want to tag this article.)

Share This Article

Send To Facebook Link

Tweet This Link

Send To LinkedIn Link

Send To StumbleUpon Link

Digg This Link

Send To Google Plus One Share Link

Send To Reddit Link

Send To Tumblr Link

Send To Delicious Link

Send To FriendFeed Link

Send To Diigo Link

Email Link

AddThis Link

0 Comments

Leave Comment (Sign in and be the first to comment on this article.)

Important

This site cannot guarantee the accuracy of articles, comments, answers and other types of content or media submitted by members or anonymous users and guests, and we recommend that you use common sense when following any advice or information found on this site. Read our full Content Disclaimer Agreement for further information.