CFLib.org – Common Function Library Project

cfLipsum([isFormatted])

Last updated April 29, 2010

Version: 0 | Requires: ColdFusion 5 | Library: CFMLLib

 
Rated 3 time(s). Average Rating: 4.0

Description:
This function allows for outputting lorem ipsum text on the fly. It converts a feed of lorem ipsum text from Lipsum.com into a formatted or unformatted return string for output.

Return Values:
returns a string

Example:

view plain print about
<cfoutput>Formatted Lorem Ipsum:<br />#cfLipsum()#</cfoutput>
<cfoutput>Unformatted Lorem Ipsum:<br />#cfLipsum(0)#</cfoutput>

Parameters:

Name Description Required
isFormatted strips lorem ipsum text of punctuation and uppercase No

Full UDF Source:

view plain print about
<!---
 Converts a feed of lorem ipsum text into a string for output.
 
 @param isFormatted      strips lorem ipsum text of punctuation and uppercase (Optional)
 @return returns a string 
 @author Bret Feddern (bret@bricecheddarn.com) 
 @version 0, April 29, 2010 
--->

<cffunction name="cfLipsum" output="no" returntype="string" displayname="cfLipsum" hint="get a lorem ipsum string from lipsum.com">
    <cfargument name="isFormatted" type="numeric" required="no" default="1" />

    <cfset var theXML = "" />
    <cfset var theGrab = "" />
    <cfset var theLipsum = "" />
    <cfset var theLipsumFeed = "http://www.lipsum.com/feed/xml" />
    
    <!--- get the xml feed --->
    <cfhttp url="#theLipsumFeed#" method="get" resolveUrl="false" />
    
    <!--- parse and search xml for lorem ipsum --->
    <cfset theXML = XMLParse(cfhttp.filecontent) />
    <cfset theGrab = XMLSearch(theXML, "/feed") />
    
    <!--- only one lorem ipsum element in the feed --->
    <cfset theLipsum = theGrab[1].lipsum.xmltext />
    
    <!--- strips lorem ipsum text of punctuation and uppercase --->
    <cfif arguments.isFormatted neq 1>
        <cfset theLipsum = lcase(rereplacenocase(theLipsum, "[^a-z0-9 ]""""all")) />
    </cfif>
    
    <cfreturn theLipsum />
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson