I came across this php ucfirst() to make uppercase the first character of each word in a string.
$foo = 'hello world!';
$foo = ucfirst($foo);
but how can I use use regular expression and preg_match() to check, then display the error message?
if (preg_match('/\b\p{Ll}/', $mem_titlename))
{
$error = true;
echo '<error elementid="mem_titlename" message="TITLE - please use uppercase for each word."/>';
}
not sure what that expression means in the example above but I got it from somewhere which does the same job as ucfirst()…
Why use a regular expression? It seems unnecessary if
ucwords()does what you want. If so, just the following:Also note that
ucwords()does what you describe, notucfirst(). http://www.php.net/manual/en/function.ucwords.php