Search Blog Posts

PHP capitalising the first letters of each word in a sentance

I recently wanted a contact form to convert a form element, in this case someones name to uppercase. For example ‘tom peters’ decided to enter his name without any capitals. The desired result would ideally be ‘Tom Peters’.

Using PHP we can convert the form field variable by doing the following:

$personsname= "tom peters";
$PersonsName = ucwords($personsname);

echo "<p>The old string - $personsname <br />";
echo "The new string - $PersonsName </p>";

There are a few more examples that you could experiment with for example:
strtolower(); will convert a string to lowercase.
strtoupper(); will convert a string to uppercase.

Tags: , , ,

Post this story to Delicious Post this story to Digg Post this story to Technorati Post this story to SumbleUpon Post this story to Facebook Post this story to Reedit

Leave a Comment

  1. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Copyright 2003-2008 Minimalistic Designs | Terms | Links | Sitemap
Website Design Liskeard - www.minimalistics.co.uk