Skip to content

View Helpers

stripLinks()

stripLinks() — returns string

Available in: controller Category: Sanitization Functions

Removes all <a> tags (hyperlinks) from an HTML string while preserving the inner text. This is useful when you want to display content without clickable links but still retain the text inside them.

NameTypeRequiredDefaultDescription
htmlstringyesThe HTML to remove links from.
encodebooleannotrueEncode URL parameters using EncodeForURL(). Please note that this does not make the string safe for placement in HTML attributes, for that you need to wrap the result in EncodeForHtmlAttribute() or use linkTo(), startFormTag() etc instead.
1. Remove links but keep text
#stripLinks('<strong>Wheels</strong> is a framework for <a href="http://www.adobe.com/products/coldfusion">ColdFusion</a>.')#

Output:
<strong>Wheels</strong> is a framework for ColdFusion.

2. Strip links from user-submitted content
userComment = '<p>Check out <a href="http://spam.com">this link</a>!</p>';
#stripLinks(userComment)#

Output:
<p>Check out this link!</p>

3. Encoding URLs (optional)
#stripLinks('<a href="http://example.com/page?param=value&another=1">Example</a>', encode=false)#

Output:
Example