jimbeeer jimbeeer - 9 months ago 45
PHP Question

Remove all html tags from php string

I want to display the first 110 characters of a database entry. Pretty easy so far:

<?php echo substr($row_get_Business['business_description'],0,110) . "..."; ?>

But the above entry has html code in it that's been entered by the client. So it displays:

<p class="Body1"><strong><span style="text-decoration: underline;">Ref no:</span></strong> 30001<strong></stro...

Obviously no good.

I just want to strip out all html code, so I need to remove everything between < and > from the db entry THEN display the first 100 chars.

Any ideas anyone?


use strip_tags

$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);   //output Test paragraph. Other text

<?php echo substr(strip_tags($row_get_Business['business_description']),0,110) . "..."; ?>