to_titlecase

Convert a string to titlecase

Definition

string to_titlecase(string $string, string $culture)

Converts $string to title case in a given $culture. The $culture defines the correct capital letter choice, rather than title capitalization rules.

Parameters

string $string

String to convert to title case.

string $culture

String defining the culture to correctly capitalize letters from other languages.

Returns

string

$string after capitalizing only the starting letter of each word, except the words completely in upper case, which are assumed to be acronyms and are therefore unchanged.

Examples

{
  a: to_titlecase('lowercase', 'en-US'),
  b: to_titlecase('UPPERCASE', 'en-UK'),
  c: to_titlecase('An unusually CASED Sentence. or Two.', 'en-DK'),
  d: to_titlecase('A title in a different culture', 'tr-TR'),
  e: to_titlecase('123', 'en-US'),
  f: to_titlecase(`true`, 'en-US'),
  g: to_titlecase(`null`, 'en-US')
}
{
  "a": "Lowercase",
  "b": "Uppercase",
  "c": "An Unusually Cased Sentence. Or Two.",
  "d": "A Title İn A Different Culture",
  "e": "123",
  "f": null,
  "g": null
}