I am using the following code to capitalize each word in a sentence, but I am unable to capitalize words with brackets attached.
PHP Code:
$output = ucwords($str, ' [{(');
echo $output;
// output ->
// [This Is The {Command Line (Interface
Update: general solution. Here a "bracket" - is any non-letter character. Any letter, following the "bracket" is converted to uppercase.
$string = "test is the {COMMAND line -STRET (interface 5more 9words #here";
$strlowercase = strtolower($string);
$result = preg_replace_callback('~(^|[^a-zA-Z])([a-z])~', function($matches)
{
return $matches[1] . ucfirst($matches[2]);
}, $strlowercase);
var_dump($result);
// string(62) "Test Is The {Command Line -Stret (Interface 5More 9Words #Here"
Live demo