php - Capitalise Name and Initials in a String -


i have number of records store names in varying combinations, e.g. -

first_name  | last_name joe         | bloggs jane louise | smith jb          | smith b         | jones 

i need displays these names in proper case -

full_name joe bloggs jane louise smith jb smith ab jones 

i know php has various built-in functions converting string uppercase, lowercase, first letter capitalised, etc can't find handle initials correctly.

does have script this? alternatively, if possible in mysql option.

select concat(upper(substring(firstname, 1, 1)), lower(substring(firstname 2))) properfirstname 

from mysql website

so problem:

select case when length(first_name) = 2 or (length(first_name) = 3 , first_name '% %')  -- check if initials first name             concat(upper(replace(first_name, " ", "")),                                   -- initials in upper, no spaces                         " ",                          upper(substring(last_name, 1, 1)),                                    -- first letter last name                         lower(substring(last_name 2)))                                   -- rest last name             else (case when first_name '% %'                                              -- check if first_name contains space                        concat(upper(substring(first_name, 1, 1)),                                    lower(substring(first_name, 2, instr(first_name, " ")-2)),                                    " ",                                    upper(substring(first_name, instr(first_name, " ")+1, 1)),                                    lower(substring(first_name instr(first_name, " ")+2)),                                      " ",                                                         -- space between first , last name                                    upper(substring(last_name, 1, 1)),                           -- first letter last name                                    lower(substring(last_name 2)))                          -- rest last name                        else concat(upper(substring(first_name, 1, 1)),                          -- first letter first name                                    lower(substring(first_name 2)),                         -- rest first name                                    " ",                                                         -- space between first , last name                                    upper(substring(last_name, 1, 1)),                           -- first letter last name                                    lower(substring(last_name 2))) end)end propername    -- rest last name 

not pretty though


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -