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 Link to comment https://forums.phpfreaks.com/topic/116565-solved-changing-string-capitalization/ 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). Link to comment https://forums.phpfreaks.com/topic/116565-solved-changing-string-capitalization/#findComment-599358 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"); Link to comment https://forums.phpfreaks.com/topic/116565-solved-changing-string-capitalization/#findComment-599359 Share on other sites More sharing options...
JonnoTheDev Posted July 25, 2008 Share Posted July 25, 2008 MFHJoe's code is also good Link to comment https://forums.phpfreaks.com/topic/116565-solved-changing-string-capitalization/#findComment-599362 Share on other sites More sharing options...
willpower Posted July 25, 2008 Author Share Posted July 25, 2008 thanks to you both Link to comment https://forums.phpfreaks.com/topic/116565-solved-changing-string-capitalization/#findComment-599363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.