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?
The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter.
To strip out all the HTML tags from a string there are lots of procedures in JavaScript. In order to strip out tags we can use replace() function and can also use . textContent property, . innerText property from HTML DOM.
Which function is used to remove all HTML tags from a string passed to a form? Explanation: The function strip_tags() is used to strip a string from HTML, XML, and PHP tags.
Approach: Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.
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) . "..."; ?>
Use PHP's strip_tags() function.
For example:
$businessDesc = strip_tags($row_get_Business['business_description']); $businessDesc = substr($businessDesc, 0, 110); print($businessDesc);
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