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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson