willpower Posted July 25, 2008 Share Posted July 25, 2008 $string = "foo bar"; echo ucwords($string) //prints Foo Bar but if $stringwithapostrope="mike o'leary"; how do i get correct capitalistion after the ' so i get "Mike O'Leary" rather than "Mike O'leary" Thanks Quote Link to comment Share on other sites More sharing options...
MFHJoe Posted July 25, 2008 Share Posted July 25, 2008 I just did a quick test and: mb_convert_case($string, MB_CASE_TITLE, "UTF-8"); Appears to work. You may have to chage the UTF-8 to the encoding of your page (although it will probably work anyway). Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 25, 2008 Share Posted July 25, 2008 If this is a standalone string then a simple string replace on the letter l would do it but i'm guessing you have a series of strings so a function would be best. function capitalizeName($name) { $name = str_replace("'", " ' ", $name); $name = ucwords($name); $name = str_replace(" ' ", "'", $name); return $name; } print capitalizeName("joe bloggs")."<br />"; print capitalizeName("mike o'leary"); Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 25, 2008 Share Posted July 25, 2008 MFHJoe's code is also good Quote Link to comment Share on other sites More sharing options...
willpower Posted July 25, 2008 Author Share Posted July 25, 2008 thanks to you both Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.