Hi, I have the following code to change the capitalisation of some text. For the most part it works great but for text with an apostrophe it needs changing. For example it transforms "i don't want to miss a thing" to "I Don'T Want To Miss A Thing" but I want it to be "I Don't Want To Miss A Thing". <?php function make_ucwords_work($string2){ $new2 = preg_replace('/\b[a-z]/e', "strtoupper('$0')", $string2); return $new2; } ?> PHP:
hello try this <?php function make_ucwords_work($string2){ $a=explode(" ",strtolower($string2)); $b = array_map("ucfirst", $a); $new2=implode(" ",$b); return $new2; } ?> PHP: Best
That's that fixed that problem, but now the first letter in brackets () isn't capitalised... e.g. It's So Hard To Say (live) instead of It's So Hard To Say (Live) Any ideas? Thanks
PHP's built in ucwords should work: $string = "it's so hard To say (live)"; echo ucwords($string)); PHP: