← All docs

strip_tags()

Strips HTML and PHP tags from a string. Optional `$allowed_tags` is a string like `"<p><a>"` or an array of tag names. Weak callers also coerce scalars and Stringable objects; strict callers require `array|string|null`.

strip_tags()

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

Strips HTML and PHP tags from a string. Optional $allowed_tags is a string like "<p><a>" or an array of tag names. Weak callers also coerce scalars and Stringable objects; strict callers require array|string|null.

Parameters:

  • $string (string)
  • $allowed_tags (array|string|null), default null, optional

Returns: string

Availability

Examples:

echo strip_tags("<p>Hello <b>World</b></p>");
echo strip_tags("<p>Hello <b>World</b></p>", "<p>");
echo strip_tags("<p>Hello <b>World</b></p>", ["p"]);

Internals

For how strip_tags is implemented in the compiler, see the internals page.