Skip to content

View Helpers

stripLinks()

stripLinks() — returns string

Available in: controller Category: Sanitization Functions

Removes all links from an HTML string, leaving just the link text.

Defaults to false (configurable per-function via set(functionName=“stripLinks”, encode=true)). These helpers strip markup; they are NOT an escaping strategy — when the goal is XSS-safe output, use h() / hAttr() instead.

NameTypeRequiredDefaultDescription
htmlstringyes—The HTML to remove links from.
encodebooleannotrueWhether to HTML-encode the remaining text after stripping.
// 1. Remove a link from an HTML string, leaving only the link text
result = stripLinks('<strong>Wheels</strong> is a framework for <a href="http://www.adobe.com/products/coldfusion">ColdFusion</a>.');
// result -> "<strong>Wheels</strong> is a framework for ColdFusion."

// 2. Strip multiple links from a string
result = stripLinks('Visit <a href="https://cfwheels.org">CFWheels</a> or read the <a href="https://cfwheels.org/docs">docs</a> for more info.');
// result -> "Visit CFWheels or read the docs for more info."

// 3. Strip links while skipping XSS encoding (e.g. when you trust the source HTML)
result = stripLinks('<p>Check out <a href="https://cfwheels.org">CFWheels</a>!</p>', encode=false);
// result -> "<p>Check out CFWheels!</p>"