{striptags:string:allowed_tags}

Description

Removes HTML and PHP tags from a string and returns the plain text between them. It is the AA counterpart of the PHP strip_tags function. The first argument is the text to clean; an optional second argument lists tags to keep (for example b and i in angle brackets), and every tag not on that list is removed. The text inside removed tags is always kept. Typical use is flattening rich-text into a plain-text field, such as an item abstract written into a calendar or RSS feed.

Parameters

string required

The text to clean. Any value works; an empty string yields an empty result.

allowed_tags optional default empty (strip every tag)

A list of tags to KEEP, written as the tag names in angle brackets with no spaces, for example <b><i><a>. Every other tag is removed. Leave empty to strip all tags. Attributes inside a kept tag are preserved.

Examples

test{striptags:<p>Hello <b>World</b></p>}
ExpectedHello World
ActualHello World
The default form removes every HTML and PHP tag, keeping the text between them.
test[{striptags:}]
Expected[]
Actual[]
With nothing between the braces the result is an empty string. The brackets here only make the empty result visible.
test{striptags:Click <a href="http://example.org">here</a> now}
ExpectedClick here now
ActualClick here now
Tags vanish but the text they wrap stays, so a link becomes plain words.
virtual{striptags:<p><b>Bold</b> and <i>italic</i></p>:<b>}
Expected(keeps the b tag: Bold and italic)
ActualBold and italic
Pass a second argument listing the tags to keep. Here only b survives; the p and i wrappers are removed. Marked virtual because the output still contains a live tag the browser would render.
test{striptags:<p>Concert at the <strong>Old Mill</strong>.</p>}
ExpectedConcert at the Old Mill.
ActualConcert at the Old Mill.
The common real-world use: flatten rich-text into plain text, for example an item abstract written into a calendar or RSS field. In practice the subject is a field getter such as the abstract; a literal stands in here so the test is deterministic.