Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP Function Remove All HTML Tags In PHP

Function Remove All HTML Tags In PHP

PHP has a function called strip_tags which strips all HTML and PHP tags from a string. It’s useful when you need filter submitted content from user, show a short description (excerpt) or try to search content from a string. Plus, it allows to specify which tags should not be stripped to make sure you have more options for the removing.

I usually use this function when I want to parse content from an external resource. Pull the content, remove all unnecessary strings then get most important needed strings.

PHP Remove All HTML Tags

Let check an example as below:

[php highlight=”10,12″] <?php
$str = "";
$str .= "<h1>This a header. </h1>";
$str .= "<p>This a paragraph. </p>";
$str .= "<table>";
$str .= "<tr><td>This is a HTML table with 1 column & 2 rows. </td></tr>";
$str .= "<tr><td>This is a <strong>bold</strong> text. </td></tr>";
$str .= "</table>";

echo strip_tags($str) . "\r\n";

echo strip_tags($str,"<h1><p>");
?>
[/php]

Output:

[text]

This a header. This a paragraph. This is a HTML table with 1 column & 2 rows. This is a bold text.

<h1>This a header. </h1><p>This a paragraph. </p>This is a HTML table with 1 column & 2 rows. This is a bold text.

[/text]

The strip_tags on line 10, all HTML tags are removed. And strip_tags on line 12, all HTML tags are removed except tags: <h1> and <p>.

Aug 30, 2011Hoan Huynh
In Top 100k Alexa Website Ranking After 6 Months LaunchingHow To Save PHP Error Log To File In IIS
You Might Also Like:
  • Create Stacked Column Chart With HTML & JavaScript
  • How To Get WordPress Tags By Categories
  • WordPress Delete Unused Post Tags By SQL Command
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • How To Track Website With Multiple Google Analytisc Accounts
  • Count Total Rows For All Tables In MS SQL Server
  • Jquery checkbox checked
  • C# ASP.NET Remove leading and trailing quotes(‘) or double quotes (“)
  • Javascript LTrim,RTrim,Trim function
  • Delete Bulk Draft And Trash WordPress Posts Includes All Tags, Comments, Meta Fields And Terms Associated
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago PHPstrip_tags226
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,170 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,044 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,826 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,307 views
C# Read Json From URL And Parse/Deserialize Json
9,794 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • How to Compose Your Essay To Me – 4 Easy Steps to Write My Essay
  • How to Find a Photo Editor
  • Installment Loans – Making Sense of Online Software
  • Apple Pay Casino Canada
  • Casinos austria
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (105)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development