• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create NameCase Function

I've got a few hours of Codeigniter under my belt, but I haven't yet tackled Helpers or Libraries much yet.

I would like to create a function that 'tries' to properly capitalize people's names. There is something similar for Ruby. My question is what is the best way for me to implement something like this? I'm mainly going to utilize it for processing form inputs for our customer database. The forms will be filled out by employees, and in theory should be somewhat neat, but I would really like to try and control capitalization.

Any help would be great!!


[quote author="InsiteFX" date="1327046798"]PHP.NET

I've seen the ucwords function before, but discovered the notes just a bit ago.

I ended up creating a helper extension of the string_helper. Not sure if I did it right, but it works so far. It's pretty simple thus far, but as obvious names creep up, I'll tweak it.

if ( ! function_exists('nameCase'))
function nameCase($name)
  $name = strtolower($name);
    $name = join("'", array_map('ucwords', explode("'", $name)));
    $name = join("-", array_map('ucwords', explode("-", $name)));
    $name = join("Mac", array_map('ucwords', explode("Mac", $name)));
    $name = join("Mc", array_map('ucwords', explode("Mc", $name)));
    return $name;

[eluser]Bhashkar Yadav[/eluser]
You can creat a new helper for extra functionality :

Create a file into your application/helpers directory and name it like helpername_helper.php. Define your function to perform specific task.

Call it like
and use the helper method like

$aa = helper_method($name);

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.