Category

HTML

Category

Today, We are going to learn PHP remove HTML tags from a string. We can remove HTML tags from the string using two ways. First, PHP provides the strip_tags function for removing HTML tags and preg_replace function for removing HTML tags from a string, Today, We learn both functions with the example.

  • Remove HTML tags using strip_tags function
  • Remove HTML tags using preg_replace function

PHP remove HTML tags from a string

We are going to learn the first example using strip_tags function.

Remove HTML tags using strip_tags function

We are using the strip_tags function for removing the HTML tags from the string. So, it’s very easy to remove HTML tags from a string. But the “strip_tags” add space after removing the tags from the string like.

The output of the above statement is “Hello world!” instead of “Helloworld!”.

So, let’s see the second example for removing HTML tags from a string and get the output like “Helloworld!” instead of “Hello world!”.

Remove HTML tags using preg_replace function

The output of the above function is “Helloworld!” instead of “Hello world!”.

We check the both function with the example Now, choose the which function is helpful for you and use it for removing HTML tags from a string.

If you face any issue after using above code please write the comment below.