CFLib.org – Common Function Library Project

detableize(string)

Last updated August 25, 2005
Download UDF

author

Jared Rypka-Hauer                                 Jared Rypka-Hauer

Version: 1 | Requires: ColdFusion MX | Library: StrLib

 
Rated 1 time(s). Average Rating: 5.0

Description:
Handy for scraping screens. This will strip all table, tr, td, and th tags from a string. It also removes leading whitespace and extra newline characters to eliminate code formatting.

Return Values:
Returns a string.

Example:

<cfset htmlString = "<table>
    <tr>
        <th width="
"18"" height=""11"">
            this
        </th>
    </tr>
    <tr>
        <td>
     | | is (test whitespace stripping)
        </td>
    </tr>
    <tr bgcolor="
"red"">
        <td>
            some
        </td>
    </tr>
    <tr>
        <td>
            test
        </td>
    </tr>
    <tr>
        <td>
            code
        </td>
    </tr>
</table>"
>


<cfoutput>
#htmlCodeFormat(htmlString)#
<br><br>
#htmlCodeFormat(detableize(htmlString))#
</cfoutput>

Parameters:

Name Description Required
string String to format. Yes

Full UDF Source:

<!---
Strips all table and table content tags and extra whitespace from a string.

@param string      String to format. (Required)
@return Returns a string.
@author Jared Rypka-Hauer (jared@web-relevant.com)
@version 1, August 25, 2005
--->

<cffunction name="detableize">
    <cfargument name="string" type="string" required="true" />
    <cfset var outputString = arguments["string"]>
    <cfset outputString = reReplaceNoCase(outputString , "</*table>", "", "all")>
    <cfset outputString = reReplaceNoCase(outputString , "</*t[rhd](\s*\w*=*""*\w*""*)*>", "", "all")>
    <cfset outputString = reReplaceNoCase(outputString , "(?m)^\s*", "", "all")>
    <cfset outputString = reReplaceNoCase(outputString , "\n{2,}", "#chr(10)#", "all")>
    <cfreturn outputString />
</cffunction>

Search CFLib.org


Latest Additions

Tony Felice Tony Felice added
writeStateSelect
14 hour(s) ago

Tony Felice Tony Felice added
varNameToText
14 hour(s) ago

Larry C. Lyons Larry C. Lyons added
splitMX
14 hour(s) ago

Tony Felice Tony Felice added
listIsItemSimila...
15 hour(s) ago

Tony Felice Tony Felice added
listCountItemSim...
15 hour(s) ago

Top Rated

Rob Brooks-Bilson                                 ListCompare
Rated 5.0, 6 time(s)

Nathan Dintenfass                                 QueryStringChang...
Rated 5.0, 4 time(s)

Rob Brooks-Bilson                                 FormatSSN
Rated 5.0, 2 time(s)

Ben Forta                                         DollarAsString
Rated 5.0, 2 time(s)

Ed Hodder                                         CapFirstTitle
Rated 5.0, 2 time(s)

Created by Raymond Camden / Design by Justin Johnson