To remove all HTML tags from a string in php, the easiest way is to use the strip_tags() function.
strip_tags() tries to return a string with all NULL bytes, HTML and php tags remove from a given string.
We can get rid of the HTML tags in a string by simply passing a string to strip_tags().
Below is a simple example of getting stripping the HTML tags from a string in php with strip_tags().
$string_with_html_tags = "<p>I'm a string with <span>HTML</span>!</p>";
echo strip_tags($string_with_html_tags, "<p>");
//Output:
<p>I'm a string with HTML!</p>
Hopefully this article has been useful for you to learn how to use the strip_tags() function to remove HTML tags from a string in php.
Leave a Reply