CFLib.org – Common Function Library Project

XHTMLParagraphFormat(string[, attributeString])

Last updated July 02, 2008

author

Jeff Howden

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns a string that starts with an opening paragraph tag, ends with a closing paragraph tag, has all CR/LF replaced with closing and then opening paragraph tags, and also accepts an optional argument that can be used to assign attributes to all opening paragraph tags inserted into the string.

Return Values:
Returns a string.

Example:

<cfsavecontent variable="myVar">The nice thing about this function is that it will allow you to pass a string representing additional attributes to apply each opening paragraph tag applied to the string.
Additionally, unlike the built-in ParagraphFormat() function, the string returned by the function begins with an opening paragraph tag (&lt;p&gt;) and ends with a closing paragraph tag (&lt;/p&gt;).  It also inserts a closing paragraph tag (&lt;/p&gt;) before starting the next paragraph.
Finally, for those of you who like to have your applications generate nicely formatted HTML, this tag breaks each paragraph on to a separate line.</cfsavecontent>

<cfoutput>#XHTMLParagraphFormat(myVar, "style=""font-family: tahoma; font-size: 12px; color: ##000099""")#</cfoutput>

Parameters:

Name Description Required
string String you want XHTML formatted. Yes
attributeString Optional attributes to assign to all opening paragraph tags (i.e. style=""font-family: tahoma""). No

Full UDF Source:

/**
 * Returns a XHTML compliant string wrapped with properly formatted paragraph tags.
 * 
 * @param string      String you want XHTML formatted. (Required)
 * @param attributeString      Optional attributes to assign to all opening paragraph tags (i.e. style=""font-family: tahoma""). (Optional)
 * @return Returns a string. 
 * @author Jeff Howden (cflib@jeffhowden.com) 
 * @version 1, July 2, 2008 
 */
function XHTMLParagraphFormat(string)
{
  var attributeString = '';
  var returnValue = '';
  if(ArrayLen(arguments) GTE 2) attributeString = ' ' & arguments[2];
  if(Len(Trim(string)))
    returnValue = '<p' & attributeString & '>' & Replace(string, Chr(13) & Chr(10), '</p>' & Chr(13) & Chr(10) & '<p' & attributeString & '>', 'ALL') & '</p>';
  return returnValue;
}

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