SQL UDF to Convert Uppercase to Propercase

So, I figured that it would be a good idea to try and expand Florida Search Engine Optimization web coverage beyond the Miami, Fort Lauderdale areas. So, I started a project to build a quazi regional network in my site. At first, I tried to be creative and store all of the cities and counties of Florida in an array with the counties as an array of structs.

With some work, I was able to get this running. However, I realized that if and when I want to make changes or additions to the cities or counties, it was going to be quite a bit of work.

After some consideration I decided that it would be much easier to just use a database table with the cities and counties.

Now, everything was going quite well with the addition of the new database when I found that the city and county fields were all in uppercase ... I really didn't want to leave the data like that, so I decided to figure out how to change the 80,000 plus records to propercase, and I found just the thing ... a cool little T-SQL UDF ... that changes the data to propercase ... the code follows ...

create FUNCTION PROPERCASE
(
--The string to be converted to proper case
@input varchar(8000)
)
--This function returns the proper case string of varchar type
RETURNS varchar(8000)
AS
BEGIN
IF @input IS NULL
BEGIN
--Just return NULL if input string is NULL
RETURN NULL
END

--Character variable declarations
DECLARE @output varchar(8000)
--Integer variable declarations
DECLARE @ctr int, @len int, @found_at int
--Constant declarations
DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int

--Variable/Constant initializations
SET @ctr = 1
SET @len = LEN(@input)
SET @output = ''
SET @LOWER_CASE_a = 97
SET @LOWER_CASE_z = 122
SET @Delimiter = ' ,-'
SET @UPPER_CASE_A = 65
SET @UPPER_CASE_Z = 90

WHILE @ctr <= @len
BEGIN
--This loop will take care of reccuring white spaces
WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0
BEGIN
SET @output = @output + SUBSTRING(@input,@ctr,1)
SET @ctr = @ctr + 1
END

IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a AND @LOWER_CASE_z
BEGIN
--Converting the first character to upper case
SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1))
END
ELSE
BEGIN
SET @output = @output + SUBSTRING(@input,@ctr,1)
END

SET @ctr = @ctr + 1

WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 AND (@ctr <= @len)
BEGIN
IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A AND @UPPER_CASE_Z
BEGIN
SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1))
END
ELSE
BEGIN
SET @output = @output + SUBSTRING(@input,@ctr,1)
END
SET @ctr = @ctr + 1
END

END
RETURN @output
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

So all that was required to get this to work, was to call the UDF after it was created ...

END
RETURN @output
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--Insert your call here ...
UPDATE TABLENAME
SET fieldname=dbo.PROPERCASE(fieldname)
FROM DBNAME..TABLENAME

Now this saved me a hell of a lot of time and was a very simple and easy way to format the data the way that I wanted. Unfortunately, when I went to repeat the same action for the counties, I accidentally wrote over the city fields with the data in the counties field ... Smooth.

It would really come in handy if something like this could have been done in ColdFusion without having to create a UDF to do so ... maybe the guys over at Adobe will read this and decide that it merits inclusion into the next release.

SEO » SES URL » RegEx Cheat Sheet

Recently I have been going through the fantastic book, Mastering Regular Expressions, by Jeffrey Friedl. Since I first learned the basics of creating a URL re-write in ColdFusion from a buddy that I used to work with, I developed a crazy fascination with Regular Expressions. For the CF developers that are reading this, it may seem like really old news to you, but many of the "SEO" folks will find this to be foreign, (a programmer is laughing right now ...)

So, for the non-code oriented readers, regular expressions are a very powerful and efficient set of tools, methods and commands to manipulate strings of text and data. You might be wondering how that can be of any benefit to the SEO community. I shall attempt to explain.

The first major benefit that regular expressions offer is through SES (Search Engine Safe) URL re-writing. For Instance, let's take a URL that would be considered as "Unsafe" for search engine optimization.

~ section508.gov/index.cfm?FuseAction=Content&ID=3

Now, I am probably going to catch hell for using this URL as an example, but you have got to love the fact that the web site for Section 508 which regards usability standards, does not use search engine safe URL's. ( Is there anyone screaming 'REMatch' out there? ). There are several characters in dynamic URL's that cause search engine spiders to stop crawling - Question marks, equal signs, ampersands, and colons, are but a few to mention. So, in the example above, we could simply run the URL through a regular expression which, replaces all of the unwanted characters with ones that are search engine safe.

Since this is not a tutorial on ColdFusion's Regular expression functions, I'm only going to show an example of how this URL could be manipulated with a regular expression.

<cfset dirtyURL = ('#CGI.PATH_INFO# #CGI.QUERY_STRING#')>
<cfset fixit = #ReplaceList(dirtyURL, "?,=,&","/,/,/")#>
<cfset cleanURL = #ReReplace(fixit,"([[:space:]])","/","ALL")#>
<cfoutput>#cleanURL#</cfoutput>

So, here we simply store the URL as a string variable, and replace the unsafe characters with desirable ones.

The end result above, would take an unsafe URL, like this ...

~ section508.gov/index.cfm?FuseAction=Content&ID=3

And return a SES URL like this ...

~ section508.gov/index.cfm/FuseAction/Content/ID/3

Which, is much better for the search engine spiders to index the content on your site ... and ... "it looks prettier".

So, that is just one of the many powerful things that can be done with regular expressions, and as I learn more about them, I'll be sure to post my discoveries, delights, and not-so-friendly encounters for all to see ... (Oh joy ... )

In the mean time, I have concocted a cool little cheat sheet, based on the one from Dave's IloveJackDaniel's site ...

I'm putting it here so that I can remember what the hell all the different Metacharacters in the various flavors of RegEx syntax do.
Feel free to do with it as you will.

» RegEx Cheat Sheet «

Anchors Quantifiers Groups and Ranges
^
\A
$
\Z
\b
\B
\<
\>
Start of string
Start of string
End of string
End of string
Word boundary
Not word boundary
Start of word
End of word
*
+
?
{3}
{3,}
{3,5}
0 or more
1 or more
0 or 1
Exactly 3
3 or more
3, 4 or 5
.
(a|b)
(...)
(?:...)
[abc]
[^abc]
[a-q]
[A-Q]
[0-7]
\n

Any char except new line (\n)
a or b
Group
Passive Group
Range (a or b or c)
Not a or b or c
Letter between a and q
Upper case letter
between A and Q
Digit between 0 and 7
nth group/subpattern

Note: Ranges are inclusive.
Quantifier Modifiers
"x" ~ below represents a quantifier
x? ~ Ungreedy version of "x"
Character Classes Escape Character Pattern Modifiers
\c
\s
\S
\d
\D
\w
\W
\x
\O
Control character
White space
Not white space
Digit
Not digit
Word
Not word
Hexadecimal digit
Octal digit
\ ~ Escape Character g
i
m
s
x
e
U
Global match
Case-insensitive
Multiple lines
Treat string as single line
Allow comments and
white space in pattern
Evaluate replacement
Ungreedy pattern
Metacharacters (must be escaped)
  • ^
    $
    (
    )
    <
  • [
    {
    \
    |
    >
  • .
    *
    +
    ?
POSIX Special Characters String Replacement (Backreferences)
[:upper:]
[:lower:]
[:alpha:]
[:alnum:]
[:digit:]
[:xdigit:]
[:punct:]
[:blank:]
[:space:]
[:cntrl:]
[:graph:]
[:print:]

[:word:]
Upper case letters
Lower case letters
All letters
Digits and letters
Digits
Hexadecimal digits
Punctuation
Space and tab
Blank characters
Control characters
Printed characters
Printed characters and
spaces
Digits, letters and
underscore
\n
\r
\t
\v
\f
\xxx
\xhh
New line
Carriage return
Tab
Vertical tab
Form feed
Octal character xxx
Hex character hh
$n
$2
$1
$`
$'
$+
$&
nth non-passive group
"xyz" in /^(abc(xyz))$/
"xyz" in /^(?:abc)(xyz)$/
Before matched string
After matched string
Last matched string
Entire matched string
Assertions Sample Patterns
?=
?!
?<=
?!= or ? ?>
?()
?()|
?#
Lookahead assertion
Negative lookahead
Lookbehind assertion
Negative lookbehind
Once-only Subexpression
Condition [if then]
Condition [if then else]
Comment
Pattern
([A-Za-z0-9-]+)
(\d{1,2}\/\d{1,2}\/\d{4})
([^\s]+(?=\.(jpg|gif|png))\.\2)
(^[1-9]{1}$|^[1-4]{1}[0-9]{1}$|^50$)
(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)
((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15})

(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})
(\<(/?[^\>]+)\>)
Will Match
Letters, numbers and hyphens
Date (e.g. 5/3/2008)
jpg, gif or png image
Any number from 1 to 50 inclusive
Valid hexadecimal colour code
String with at least one upper case
letter, one lower case letter, and one
digit (useful for passwords).
Email addresses
HTML Tags
Note: These patterns are intended for reference purposes and have not been
extensively tested. Please use with caution and test thoroughly before use.


Florida SEO Try Catch Application.CFC

Okay, so I am only a year in to CF development now, and I still feeling about as confident with my skills as well, the first month I started ... don't ask me why, but I always seem to find a problem that baffles me. This time is not an exception.

I recently moved to Application.CFC ... (Don't know what that is? Don't worry, I know as much as you. Want to find out more? ... Ray "Raymond" has info on his site ... )

So, this move came about since I had no idea how to manage error handling for 404 pages in CF ... for instance, if a link to a page on my site was missing, or broken ... the 404 page would get returned. However, if someone requested a .cfm page that did not exist whatsoever ... then the "IIS" template would kick in ... Not Good ...

So, I wanted my 404 template to kick in even when someone requested a specific ColdFusion page as well as broken links, moved pages, anything else ...

The only way to get what I really needed ... a default error handler in CF for all pages ... was not going to be available on a shared hosting platform ... which my site is on ... Good thing that ColdFusion 8, has the functionality available by way of the onMissingTemplate function through Application.CFC ...

Now, I saw a few references regarding the cflocation tag ...

<cffunction name="onMissingTemplate" returnType="boolean" output="false">
   <cfargument name="thePage" type="string" required="true">
   <cflog file="somefiles" text="#arguments.thePage#">
   <cflocation url="404.cfm?thepage=#urlEncodedFormat(arguments.thePage)#" addToken="false">
</cffunction>

But this was a problem due to redirecting from a 404 page ... The search engines would definitely have a problem with a 404 page returning a "page moved temporarily" or a "page moved permanently" flag when in fact it didn't exist at all ... That would Not be good for the rankings ...

So, the answer it seems was to try a bit of a different solution ... similar, yet a bit different ... here's the next shot ...

<cffunction name="onMissingTemplate" returnType="boolean" output="true">
   <cfargument name="targetPage" type="string" required="true" />
   <cflog file="somefile" type="error" text="Missing template: #Arguments.targetPage#">
   <cfinclude template="404.cfm" />
   <cfreturn true />
</cffunction>

Generally it's not a real smart idea for a newbie coder such as myself to go playing around with really important functions on a production site ... but, then again I can't have problems with 404 pages either ... So, I chanced fate ... and came up with the solution above ...

I also created a custom 404 page which I am rather fond of ... if an event fires my 404 template ... I have an include of my site map so search engine robots can give me a some credit by crawling the sitemap ... and at the same time, I can offer my visitors a useful way to navigate a page that they might have been looking for ...

You have been warned! If, you decide to use a 404 page ... make sure that you don't include it either in your .xml site map ... and that you implement a header status 404 ...

<cfheader statuscode="404" statustext="Not Found" />

Furthermore, pay attention to your Meta Robots Tag ...

<meta name="robots" content="noindex, follow" />

If not ... you are basically telling the search engines that your pages exist ... (status 200 » okay ) ... and that will kill your search engine optimization efforts ... fast.

CF 8 Image CAPTCHA » toScript JS Validation

I finally got to the point where I had seen just about as much spam that I could handle and being somewhat of a ColdFusion developer, I decided to take some action ...

My first shot at stopping the pesky spammers was by implementing a Lyla CAPTCHA. However, I had some problems getting the CFC working correctly, and after several failed attempts, I tried to use Rob Gonda's AjaxCFC with Lyla too ... Yet, I still wasn't able to get the CAPTCHA working ...

So, after talking with a friend, that is quite familiar with ColdFusion ... he asked me why I didn't just use CF8's native support for CAPTCHA's with the CF Image tag ...

I really hadn't even thought of it ... I found the answer ...

I learned quite a bit more CF code in order to get the image going along with some JS validation ... For starters, I got the base idea from Camden's example of using CF CAPTCHA ... but I didn't want to break the layout of my form page by expanding the form during validation error messages ... I had to find a way to convert Ray's form validation in to JavaScript validation ...

Well, I searched through hundreds of pages in order to find a solution to my problem ... How to turn ColdFusion variables ... in to JavaScript variables ... I didn't have a clue ... until I found another non-related tutorial example by ... (guess who ...) yep, it's Ray again ... that alluded to the toScript method ... almost everywhere else I had searched, returned answers which expresses that there was no way in converting a ColdFusion object in to a JavaScript object ...

So, I was one step closer to my goal ... then, I hit another obstacle ... the error strings all ended with a "<br />" in order to separate the error strings when returned to the page ... that would not convert in to a JavaScript variable ... New Problem ... how could I insert a line break » Carriage Return in to a ColdFusion variable ... and return it in JavaScript without throwing errors?

Thanks to the friendly Ben Nadel ... for his contributions to the CF community again ... where I found a post of his on converting CF characters to JS ...

So, with a bit of my own efforts some where in there ... I finally have a CF CAPTCHA on my site ... and can say good bye to the spammers ... bye spammers ... 

BlogCFC XML-RPC & Windows Live Writer

I recently decided to take a shot at creating Blog entries to BlogCFC through a desktop publishing application. ScribeFire, is a nice tool that offers the ability to create Blog posts directly to from Firefox. Yet, it lacked quality functionality and support that is required for those that are doing serious publishing. While searching through the ColdFusion Blogging community lately, I  ran across several articles suggesting the use of Google Docs as a method for posting to BlogCFC too. I really didn't  care for that method either.

So I managed to find a reference on Ray Camden's Blog to using Windows Live Writer via XML-RPC.  BlogCFC has been supporting XML-RPC for some time now, so I was eager to start using it after I figured out what it was actually was capable of doing. For those that are not familiar with XML-RPC, it is a specification that allows connections between two computers through remote procedure calls to XML.

The reference on Ray's site was to a demo from Dan Vega, which explains how to get the writer up and running. Several things have to be pointed out though. First, the categories from BlogCFC are not editable from WLR. To edit those, you'll have to go in to the BlogCFC admin. Second, the style sheets from BlogCFC don't seem to import correctly. That doesn't seem to carry over in the post though so personally I can handle dealing with it. Another thing is, deleting posts from within WLR, will remove the entry from the Blog, but not from the xmlrpc.cfm cache or, rather the ScopeCache.cfm template ... in order to deal with that, you might want to add the code below to the xmlrpc.cfm file, just below the blogger.deletePost case switch statement around lines 185-190.

<!--- clear cache --->       <cfmodule clearall="true" scope="application" template="../tags/scopecache.cfm">

This way the Blog's cache will update whenever you delete a post ... Much thanks goes out to Shane for that.

All and all, I must admit that editing in WLR is very clean - much nicer than working directly in an online editor, and though WLR does not have the power of a word processor, or the design and HTML editing capabilities of an IDE, it is still a nice tool to use for creating blog posts.

Ajax Framework for ColdFusion

As always, I am looking to expand my knowledge and understanding in Rich Internet Application development. Lately, I have been researching throughout the ColdFusion and Object Oriented communities for a solid framework that will be a good foundation for me to grow and learn in developing Ajaxian applications in a ColdFusion environment.

The first contender for my needs is JQuery. For reasons based on personality as well as principle, the ColdFusion "sensei" in whom I follow, Ben Nadel, seems to use the JQuery framework and I've adopted a tendency to trust his lead. There are several other options available as well that I have not set aside however. The mootools and prototype sets look rather attractive as well. If there are any JavaScript / Ajax pros out there that are familiar with frameworks for ColdFusion please let me know your thoughts.

ColdFusion Components and OO Java - Closely Related - Not the Same

Recently I have been reviewing ColdFusion 8 - Beyond the Basics by David Gassner and I have ventured into the world of ColdFusion Components (CFC's). I am starting to get a better understanding of how ColdFusion, or CFML Pages, are processed in the JRun server and how CFC's relate somewhat to Object Oriented Java. First of all I had to find out that the CFML alone is not related to Java. However, there is an ability in ColdFusion to integrate in a hybrid environment with Java through the use of CFC's.

Since I am very new to CFC's, I will not attempt to explain the complex architecture that is involved in relating ColdFusion to Java, but rather what it is that I came to realize from the Beyond the Basics series and by doing a little research on CFC's and Java.

[More]

Welcome to ColdFusion (Java?) Programming

Nine months ago I started to learn how to program in ColdFusion. At that time, I had never programmed before, but I was holding my torch up high for my quest in learning to be a programmer.

My sights were really set on Java or C ++ to give me the fundamentals that I would need. However, my company is working with ColdFusion, so it just seemed practical to start with a language that I would have the most exposure to, and be able to practice the most.

So, after learning a bit of HTML, CSS and JavaScript, I decided that I should move forward and start learning to learn how to program. Taking the advice of a senior applications developer at my job, I decided that it would be a good idea to build a web site and start coding. Well, I did and now I am well on my way as a beginner and learning more at every opportunity.

Little did I know at the time I started to program, that ColdFusion Markup is basically a very large and organized library of Java programs packaged in a tag based language. Now that I have had some introductory experience with the basics of ColdFusion, I feel that I am ready to start learning some of the advanced aspects of programming and quite possibly look toward earning a certification as a ColdFusion developer.

It may be a real challenge to be working as a manager of a search engine optimization division and studying, learning and practicing for the ColdFusion certified developers exam at the same time. To pull this off, it looks like I am going to put my torch to the test and see if it keeps my midnight oil burning ...

SEO BlogCFC Moves In

This is the greatest... I have been eagerly awaiting the day that I could actually get to put the BlogCFC in to the site ... There were a lot of obstacles to work around to actually get the Blog together. First and foremost was that I had my site hosted at GoDaddy ... I am not much for slinging mud so I'll just try to leave my comment minimal.

If you are looking for ColdFusion hosting ... there are much better alternatives to the shared plan that GoDaddy provides. Do your self a BIG favor ... Keep looking. I'm happy to say that though I have only been with my new host for three days, Host My Site has delivered fantastic customer service thus far.

Next thing on the development list is to start chopping in to the CSS on this blog and see how well I can style the elements to mirror that of my site ... Well, onward to the world of CSS ... untill next time.

BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Florida Search Engine Optimization L.L.C.
Search Engine Optimization Specialist || Web Designer || Web Developer || Edward J Beckett ||
Search Engine Optimization Company  || SEO Services || Internet Marketing Company || Search Engine Optimization Expert || Florida Search Engine Optimization LLC
Florida Search Engine Optimization || Search Engine Optimization || SEO Services || Florida SEO Blog
Florida Search Engine Optimization
Search Engine Optimization
SEO Services
Florida SEO Blog
July-04-2008
1:46 AM EST