For everyone else that needs a heading, around other characters, including dashes, brackets, and parentheses. You can use the regular expression with preg_replace_callback to capture a word that is broken by a dash or begins with a character that does not contain an alphabet.
$STR = ucwords(strtolower($STR));
$STR = preg_replace_callback('/([A-Z]*)([^A-Z]+)([A-Z]+)/i',
function ($matches) {
$return = ucwords(strtolower($matches[1])).$matches[2].ucwords(strtolower($matches[3]));
return $return;
}, $STR);
source
share