❮ PHP String Reference
Example
Strip the string from HTML tags:
Try it Yourself »
Definition and Usage
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.
Note: This function is binary-safe.
Syntax
Parameter Values
string | Required. Specifies the string to check |
allow | Optional. Specifies allowable tags. These tags will not be removed |
Technical Details
Returns the stripped string |
4+ |
As of PHP 5.3.4, this function ignores self-closing XHTML tags [like ] in allow parameter As of PHP 5.0, this function is binary-safe. As of PHP 4.3, HTML comments are always stripped. |
More Examples
Example
Strip the string from HTML tags, but allow tags to be used:
Try it Yourself »
❮ PHP String Reference
I want to display the first 110 characters of a database entry. Pretty easy so far:
But the above entry has html code in it that's been entered by the client. So it displays:
Ref no: 30001
from the db entry THEN display the first 100 chars.
Any ideas anyone?
j0k
22.3k28 gold
badges77 silver badges86 bronze badges
asked Feb 4, 2013 at 9:47
1
use strip_tags
$text = 'Test paragraph.
Other text';
echo strip_tags[$text]; //output Test paragraph. Other text
answered Feb 4, 2013 at 9:48
Some Text
Lorem Ipsum is simply dummy text of the printing and typesetting industry.';
echo strip_tags_content[$srting];
function strip_tags_content[$text] {
return preg_replace['@.*?@si', '', $text];
}
Output:
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
answered Sep 4, 2016 at 18:26
Brexit deal: May admits she would have
answered Dec 10, 2018 at 17:18
Or if you have a content coming from the database;
...
answered Sep 29, 2020 at 9:39
$string = Awesome
Website by Narayan. Thanks for visiting enter code here;
$tags = array["p", "i"];
echo preg_replace['#]+]?>.*?#s', '', $string];
Try this
Bhargav Rao
47.1k27 gold badges121 silver badges136 bronze badges
answered Dec 5, 2020 at 12:28
Not the answer you're looking for? Browse other questions tagged php or ask your own question.
How do I remove a specific HTML tag from a string in PHP?
How do I remove a tag from a string?
What is strip HTML?
,
, and