How to remove html tag from string in php

❮ 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

ParameterDescription
string Required. Specifies the string to check
allow Optional. Specifies allowable tags. These tags will not be removed

Technical Details

Return Value:PHP Version:Changelog:
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

' @endphp {{ strip_tags[$description]}}

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?

PHP provides an inbuilt function to remove the HTML tags from the data. The strip_tags[] function is an inbuilt function in PHP that removes the strings form HTML, XML and PHP tags. It accepts two parameters. This function returns a string with all NULL bytes, HTML, and PHP tags stripped from a given $str.

How do I remove a tag from a string?

The HTML tags can be removed from a given string by using replaceAll[] method of String class. We can remove the HTML tags from a given string by using a regular expression. After removing the HTML tags from a string, it will return a string as normal text.

What is strip HTML?

stripHtml[ html ] Changes the provided HTML string into a plain text string by converting
,

, and

to line breaks, stripping all other tags, and converting escaped characters into their display values.

Which function is used to remove all HTML tags from a string passed to A from?

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.

Chủ Đề