How To Remove HTML Tags In PHP & MySQL – Simple Example

To remove HTML tags in PHP, we can either use the strip_tags() or htmlentities() function:

  • The strip_tags() function will remove all HTML tags. For example, $clean = strip_tags("<p>Foo</p> Bar"); will result in Foo Bar.
  • The htmlentities() function will not remove but convert all symbols into HTML entities. For example,  $clean = htmlentities("<p>Foo</p>"); will result in &lt;p&gt;Foo&lt;/p&gt;
  • Lastly, we can also create a stored function in MySQL to strip HTML tags as an alternative.