Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

strip_tags()

Remove HTML tags while retaining the text between them.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

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

Remove HTML tags while retaining the text between them. PHP blocks, including their code, are removed. Allowed HTML tag names can be passed in an array; attributes on permitted tags remain. This does not validate markup or sanitize arbitrary HTML. For text displayed in HTML, use context-appropriate escaping.

Signature

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

Example output

One <b class="note">two</b>

Examples

<?php
echo strip_tags('<p>One <b class="note">two</b></p>',["b"]);

Result

One <b class="note">two</b>

Sources