Welcome Guest, Not a member yet? Register   Sign In
Create NameCase Function
#1

[eluser]jamgood96[/eluser]
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!!
#2

[eluser]InsiteFX[/eluser]
PHP.NET
ucwords
#3

[eluser]jamgood96[/eluser]
[quote author="InsiteFX" date="1327046798"]PHP.NET
ucwords
[/quote]

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.

Code:
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;
}
}
#4

[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
Code:
$this->load->helper('helpername');
and use the helper method like

Code:
$aa = helper_method($name);




Theme © iAndrew 2016 - Forum software by © MyBB