Question #6177   Submitted by Answiki on 05/22/2022 at 03:32:52 PM UTC

In PHP, how to remove HTML tags from a string?

Answer   Submitted by Answiki on 05/22/2022 at 03:42:38 PM UTC

The PHP function strip_tags() removes HTML, XML and PHP tags from a string. Here is an example where all the tags are deleted

$string = "<h1>Title</h1>";

// Displays: Title
echo strip_tags ($string);

The following example removes all the tags except <b> and <i> :

$string = '<div><b>Bold</b> and <i>italic</i> text</div>';

// Dispays: <b>Bold</b> and <i>italic</i> text
echo strip_tags ($string, '<b><i>');

See also:


3 events in history
Answer by Answiki on 05/22/2022 at 03:42:38 PM

The PHP function strip_tags() removes HTML, XML and PHP tags from a string. Here is an example where all the tags are deleted

$string = "<h1>Title</h1>";

// Displays: Title
echo strip_tags ($string);

The following example removes all the tags except <b> and <i> :

$string = '<div><b>Bold</b> and <i>italic</i> text</div>';

// Dispays: <b>Bold</b> and <i>italic</i> text
echo strip_tags ($string, '<b><i>');

See also:


Answer by Answiki on 05/22/2022 at 03:40:12 PM

The PHP function strip_tags() removes HTML, XML and PHP tags from a string. Here is an example where all the tags are deleted

$string = "<h1>Title</h1>";

// Displays: Title
echo strip_tags ($string);

The following example removes all the tags except <b> and <i> :

$string = '<div><b>Bold</b> and <i>italic</i> text</div>';

// Dispays: <b>Bold</b> and <i>italic</i> text
echo strip_tags ($string, '<b><i>');

Voire aussi :


Question by Answiki 05/22/2022 at 03:32:52 PM
In PHP, how to remove HTML tags from a string?
# ID Query URL Count

Icons proudly provided by Friconix.