Take two strings:
"o'sulLivAn"
"doUble-baRrel"
Desired result:
"O'Sullivan"
"Double-Barrel"
I thought ucwords(strtolower($str)) might do the trick but it treats the strings as a single word.
I know I can explode, or rather preg_split the string and then capitalize the parts and put it back together again, but I’m wondering if there’s a better way of doing it?
Usually with PHP and this sort of thing there tends to be a function hiding away somewhere that’d be useful but isn’t obvious or well known.
There’s no php function to do this.
Here’s a one-liner with no loop (kinda)