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 Facebook0Share 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 make a call using Twilio?

Posted on 1 year ago

Ankit Shah

Table layout using DIV tags

Posted on 5 years ago

Bhumi

Five Reasons Why You Should Go With PHP

Posted on 4 years ago

Bhumi

How to use Git init command

Posted on 5 months ago

Bhumi

Fixed Remove class issue with MooTools

Posted on 5 years ago

Bhumi

How BlockChain and Ethereum works?

Updated 1 day ago

Bhumi

Facade implementation in Laravel

Updated 2 months ago

Bhumi

MySQL coalesce() function

Updated 18 years ago

Bhumi

How to use JavaScript Promise API?

Updated 18 years ago

Bhumi

What are Lambdas and Closures in PHP?

Updated 18 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 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 4 years ago

Bhumi