how to remove html tags from text in php

Mobile
feeds
Welcome Login | Register

how to remove html tags from text in php
Reply Your Comments:
Click this button if you are interested in replying to this topic and leave your comments
Sent To Friend
CLick this button if you want to send this page to a friend.
Subsribe To Rss Feeds
Subscribe to RSS
CLick this button if you want to subscribe to this RSS Feed. You can use your browsers feeds burners if you have mozilla or internet explorer 7 or higher and keep up with updates.
  Forums Index
      » PHP Forums
        » » how to remove html tags from text in php
how to remove html tags from text in php
Post Description: how to remove html tags from text in php PHP
Post Tags:
This Post Has Been Viewed 341 Times Since Sun Nov 30, 2008 12:49 pm Author hostman with 3 replies
how to remove html tags from text in php
Advertise On This Page




if you are reading my post, its probably because you want to remove html tags from your posts or forums or whatever.

when i first started to do this, i wanted to remove all the html tags from a strin i had in my posts. this is an example:

<?
$string = "<h1>BIG HTML TAGS</h1>";
?>


ok as you can see, this will output:

BIG HTML TAGS



but i dont want that, i want to stop and prevent html from being posted on my forums. i tried using htmlspecialchars() and htmlentities() but none did what i wanted.

but finally i found it, the function is called strip_tags()

so if i wanted to remove the <h1> tags from my string i would just simply do this:

<?
$string = "<h1>BIG HTML TAGS</h1>";
$string = strip_tags($string);
?>


and this would be the ouput:
BIG HTML TAGS


hope this helps



Leave Your Comments

Your Name
Your Email Address (Will Not Be Published)
Notify Me When Someone Replies to this Page
(An email will be sent to you when someone replies to your comments)
Your Comments
Include A Picture with your comments
Share
| More
Share this page by putting this URL in your comments to other websites like myspace, Facebook, Twitter friendster, Hi5, Groups, Boards, Forum or others. Just Copy and Paste this Code
URL:
To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it.
Embed:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
BBCODE:
Subscribe Feeds
Webmasters - Exchange Links With Us. Add related websites to this topic
Add Link:
Links Related to : how to remove html tags from text in php

Comments and replies About how to remove html tags from text in php
:: 1 :: Reply #87278 Reply By Ivan On Tue Dec 23, 2008 3:15 am
Ivan:
helped a lot, thanks!
:: 2 :: Reply #117810 Reply By micheal On Tue Oct 13, 2009 6:55 am
micheal:
what if the supplied html is not valid?
i.e
<h1>big html tags /h1>
:: 3 :: Reply #127633 Reply By Antoniraj On Mon Feb 08, 2010 8:24 am
Antoniraj:
I have the problem to display html content in the home page which means to disply less content and rest of the content has to display in the reas more page