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 inFoo Bar
. - The
htmlentities()
function will not remove but convert all symbols into HTML entities. For example,$clean = htmlentities("<p>Foo</p>");
will result in<p>Foo</p>
- Lastly, we can also create a stored function in MySQL to strip HTML tags as an alternative.