CFLib.org – Common Function Library Project

hrefsToList(inputString[, delimiter])

Last updated February 22, 2006

author

Marcus Raphelt

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Extracts all links from a given string and puts them into a list.

Return Values:
Returns a list.

Example:

<cfhttp url="http://www.yahoo.com">

<cfset links = hrefsToList(cfhttp.filecontent)>
<cfoutput>#links#</cfoutput>

Parameters:

Name Description Required
inputString String to parse. Yes
delimiter Delimiter for returned list. Defaults to a comma. No

Full UDF Source:

/**
 * Extracts all links from a given string and puts them into a list.
 * 
 * @param inputString      String to parse. (Required)
 * @param delimiter      Delimiter for returned list. Defaults to a comma. (Optional)
 * @return Returns a list. 
 * @author Marcus Raphelt (cfml@raphelt.de) 
 * @version 1, February 22, 2006 
 */
function hrefsToList(inputString) {
    var pos=1;
    var tmp=0;
    var linklist = "";
    var delimiter = ",";
    var endpos = "";
    
    if(arrayLen(arguments) gte 2) delimiter = arguments[2];
        
    while(1) {
        tmp = reFindNoCase("<a[^>]*>[^>]*</a>", inputString, pos);
        if(tmp) {
            pos = tmp;
            endpos = findNoCase("</a>", inputString, pos)+4;
            linkList = listAppend(linkList, mid(inputString, pos, endpos-pos), delimiter);
            pos = endpos;
        }
        else break;
    }

    return linkList;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson