Tag

Tags

Browsing

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.

Today, We are going to learn How to create Category tree from Array using PHP. Many times we need to create the parent and child category tree. Let’s make it easy with a single function. Yes, You can create the parent and child tree from Array using a single PHP function. Let’s follow the function and pass Array for creating parent and child category tree.

Category tree from Array

Finally, Our function is ready Now, you just need to pass the category array-like.

Now, let’s pass this Array to buildTree then check the output.

We got output something like below.

So, Our category tree is ready with parent and child hierarchy.

If you face any issue after using this code please write a comment.