107 of 410 menu

The strip_tags Function

The strip_tags function removes HTML tags from a string without affecting their content. The second optional parameter can be used to specify allowed tags - they will not be removed. Allowed tags are specified along with angle brackets.

Syntax

strip_tags(string $string, array|string|null $allowed_tags = null): string

Example

Let's remove all HTML tags from the string:

<?php $str = 'lorem <b>ipsum</b> dolor sit amet'; echo strip_tags($str); ?>

Code execution result:

'lorem ipsum dolor sit amet'

Example

Let's remove all HTML tags, except for the allowed ones:

<?php $str = 'lorem <b>ipsum</b> <i>dolor</i> <s>sit</s> amet'; echo strip_tags($str, '<b><i>'); ?>

Code execution result:

'lorem ipsum dolor <s>sit</s> amet'

See Also

byenru