CFLib.org – Common Function Library Project

GetHTMLTitle(str)

Last updated December 3, 2001

author

Raymond Camden

Version: 1 | Requires: CF5 | Library: StrLib

Description:
This UDF will parse an HTML string (normally returned from CFFILE) and return the text between the title tags. The UDF will return an empty string if it cannot find proper HTML title tags.

Return Values:
Returns a string.

Example:

<CFOUTPUT>
<CFSAVECONTENT VARIABLE="FakeHTMLFile">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Interesting Title</title>
</head>

<body>

Hello every

</body>
</html>
</CFSAVECONTENT>

<CFSET Title = GetHTMLTitle(FakeHTMLFile)>
The title of this html file is #Title#
</CFOUTPUT>

Parameters:

Name Description Required
str The HTML string to check. Yes

Full UDF Source:

/**
 * Parses an HTML page and returns the title.
 * 
 * @param str 	 The HTML string to check. 
 * @return Returns a string. 
 * @author Raymond Camden (ray@camdenfamily.com) 
 * @version 1, December 3, 2001 
 */
function GetHTMLTitle(str) {
	var matchStruct = reFindNoCase("<[[:space:]]*title[[:space:]]*>([^<]*)<[[:space:]]*/title[[:space:]]*>",str,1,1);
	if(arrayLen(matchStruct.len) lt 2) { writeoutput("error<BR>");return ""; }
	return Mid(str,matchStruct.pos[2],matchStruct.len[2]);	
}
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