Making sure a pro noun entered into a form gets capitalized.

Hi I am new and would like to have this idea criticized. I wrote a working script in attempt to ensure that an entered value is printed as capitalized but i feel it is cumbersome and should be much more simple. If anyone would like to comment on this I would greatly appreciate it.

$strg = trim($_POST[‘user_char_name’]);
$finder = ‘/^[a-z]/’;
if (preg_match($finder, $strg , $matches)){

$up_cvar = strtoupper($matches[0]);
$user_cname = preg_replace($finder , $up_cvar , $strg);
} else {
$user_cname = trim($_POST[‘user_char_name’]);

Can you post an example of ‘user_char_name’ value?

Assuming you’re not trying to put every word in caps, use ucase().

Sponsor our Newsletter | Privacy Policy | Terms of Service