by Chris Channing

Developing a web application in PHP takes a long time, depending on the complexity of the project. Thus, programmers should make use of time-saving functions that allows them to improve efficiency both for them and others who work with what they have created. One such function to delve into is UCWords- a particularly nice time-saver.

UCWords in particular is an easy function to learn since it only accepts one argument: the string that you wish to manipulate. If done correctly, the function will then be able to capitalize the first letter of every word in a given string. Similar functions such as StrToUpper will actual capitalize each letter in the string, so be sure to make the distinction between the bunch.

One of the most popular applications of the UCWords function is to ensure that user input from a form is uniform with other data received. This is quite easy to see in social networking websites, which typically automatically capitalize the name of their users on their profiles. When users receive an email, they’ll also notice their name is capitalized regardless if they capitalized it upon registration.

When webmasters want to reach a broad audience for their content, they will alter Meta tags to tell search engines how and to who they should display the webmaster’s resource. When webmasters format the “Title” tag for the Meta data, they should capitalize it to show a sense of professionalism. Using UCWords for this task is quite common, since it can dynamically do so.

By applying the UCWords function to a custom-made function, we can also alter strings to keep certain words lowercased. This is especially important for proper news resources, who know that proper title case is going to mean that some prepositions or words need to remain in lower case. By initializing an array of prepositions and selectively making them lowercased, web developers can ensure that there are no mistakes in how a title should appear.

Another gripe some PHP developers have with the UCWords function is that it won’t always display some characters correctly. But luckily for the majority of PHP developers, this won’t be a problem since this only happens with foreign characters that haven’t received language support from the development community. If a developer is affected by this, work arounds have been created, and the next release of PHP should bring solutions to this simple problem.

Final Thoughts

UCWords has much functionality to take advantage of. If you think you would like to give it a try, consider looking around for a specific tutorial with examples on coding practice.

About the Author: