Back to Top

How to clean HTML content in PHP?

Clean HTML content in PHP

After a long long time, i get time to write an article and I am curious to write but didn’t get time. So, Today I am going to explain about how to clean HTML content using PHP code.

Sometimes you want to remove HTML tags from your content.Especially when you want to display short description from the long description of content, following function is useful.It is very useful when we want to completely remove HTML code from the string.

Let’s see function to clean html content

Super Simple! This function can be very helpful to strip out all HTML tags.Here, An above little code snippet will take the sting and then used nl2br function which will replace \ n to HTML < br /> tag. then I have used preg_replace function which will replace all
tag to space. then trim and strip_tags which remove extra space and other HTML content respectively.

That’s it. Place above function into a file and call function and see magic ;).

Hope this helps someone else out.As always,Thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Share:
Share on Facebook0

Share on LinkedIn0Tweet about this on TwitterShare on Google+0Buffer this pageDigg thisShare on Reddit0

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular Posts

Learn Responsive Web Design Online

Posted on 4 years ago

Bhumi

How to Create a Custom WordPress Widget

Posted on 4 years ago

Bhumi

New Features in WordPress 3.5

Posted on 4 years ago

Bhumi

How to use HTML5 Constraint Validation

Posted on 2 years ago

Bhumi

Introduction to the Instagram API

Updated 4 weeks ago

Bhumi

How to Use the HTML5 Full-Screen API

Updated 1 month ago

Bhumi

What are Lambdas and Closures in PHP?

Updated 1 month ago

Bhumi

MySQL REGEXP Operator

Updated 1 month ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 2 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 3 years ago

Bhumi