View Helpers
stripLinks()
Signature
Section titled “Signature”stripLinks() — returns string
Available in: controller
Category: Sanitization Functions
Description
Section titled “Description”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.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
html | string | yes | — | The HTML to remove links from. |
encode | boolean | no | true | Encode 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. |
Examples
Section titled “Examples”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