Find First Paragraph

Today I had the need to create a script that would find the first paragraph in a string and use this as the extract for a news article.

So, I thought I’d share the ColdFusion code with everyone:

<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>
<cfset request.firstParagraph = findNoCase("</p>",trim(paragraphs)) />
<cfif request.firstParagraph gt 0>
    <cfset request.firstParagraph = request.firstParagraph+3 />
    <cfset request.newsExtract = left(trim(paragraphs),request.firstParagraph) />
<cfelse>
    <cfset request.newsExtract = trim(paragraphs) />
</cfif>
<textarea id="newsExtract" name="newsExtract" cols="40" rows="5">
<cfoutput>#request.newsExtract#</cfoutput>
</textarea>

I hope that others find this useful.

Update: 07 December 2006
I have now turned this into a nifty function:

<cfscript>
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;
}
</cfscript>

This should make using the code even easier.

Update: 08 December 2006
This function is now available on CFLib.org!

Print Styles Not Working In Firefox?

I’ve just recently update my freelance website design website and whilst updating the website I decided to incorporate a print stylesheet. All was working as it should in Internet Explorer, but for some reason Firefox was ignoring the print stylesheet. A little Googleing revealed that if you have titles assigned to the link tag calling the print stylesheet then Firefox ignores it.

Not sure if this is a bug, but it’s worth knowing when creating print styles (which you should be doing).

FlexiCrete Refresh

Yesterday I relaunched the FlexiCrete website. This is a website for a company in South Africa that makes easy-to-use prefabricated paving slabs / stones.

FlexiCrete
It’s the first website I’ve done in years that uses classic asp, so it was a matter of going back to the books to figure out the database code etc. I’m happy with the outcome.

The website also uses Slideshow Pro for the gallery section.

Why not go have a look?