I was wondering is there a way to escape all html tags from a a bunch of html code, and extract only the text i.e.
<strong>this is strong</strong>
<br />
<h1> this is a header</h1>
and I want to get the text between the tags only, so basically only
this is strong this is a header
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
One of the things I love about PHP...thoughtful functions for web developers.
Use strip_tags() like this:
$html = "<strong>this is strong</strong><br />\n".
"<h1> this is a header</h1>";
$text = strip_tags($html);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With