CFLib.org – Common Function Library Project

firstParagraph(str)

Last updated December 7, 2006

author

Neil Merton

Version: 1 | Requires: CF5 | Library: StrLib

Description:
This function will return the first paragraph it finds in a string. It requires that the string is properly formed (i.e. has a closing paragraph tag).

Return Values:
Returns a string.

Example:

<cfsavecontent variable="paragraphs">
<p>This is the first paragraph.</p>
<p>Here's the second paragraph.</p>
<p>And finally, the third paragraph.</p>
</cfsavecontent>
<cfoutput>#paragraphs#</cfoutput>
<textarea id="newsExtract" name="newsExtract" cols="40" rows="5">
<cfoutput>#firstParagraph(paragraphs)#</cfoutput>
</textarea>

Parameters:

Name Description Required
str String to parse. Yes

Full UDF Source:

/**
 * Finds the first paragraph in a given string.
 * 
 * @param str 	 String to parse. (Required)
 * @return Returns a string. 
 * @author Neil Merton (neil.merton@mewebdev.net) 
 * @version 1, December 7, 2006 
 */
function firstParagraph(str) {
	str = trim(str);
	endTag = findNoCase("</p>", str);
	if (endTag gt 0) {
		endTag = endTag + 3;
		extract = left(str, endTag);
	} else {
		extract = str;
	}
	return extract;
}
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