CFLib.org – Common Function Library Project

firstParagraph(str)

Last updated December 07, 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;
}

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