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

How to Create and Use Cookies in PHP

Posted on 6 months ago

Bhumi

How to use CSS3 Object-fit

Posted on 1 year ago

Bhumi

How to import terms from csv in wordpress?

Posted on 3 years ago

Bhumi

How does CI/CD works on AWS?

Updated 17 years ago

Bhumi

Overview of Amazon Web Services (AWS)

Updated 17 years ago

Bhumi

How to add ColorDots in FullCalender?

Updated 17 years ago

Bhumi

A Beginner’s Guide To Composer

Updated 17 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 1 year ago

Bhumi

The Reader’s Poll – August 2014

Posted on 2 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 2 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 2 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 3 years ago

Bhumi