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.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

What is Wpautop() function in WordPress

Posted on 3 years ago