to_sentencecase

Convert a string to sentence case

Definition

string to_sentencecase(string $string)

Converts a string to sentence case, i.e., capitalizes the first words of sentences, and sets the rest to lowercase.

Parameters

string $string

String to convert to sentence case.

Returns

string

$string after converting to sentence case. In the returned string, the starting letter and any letters following a period are capitalized, while the rest are set to lowercase.

Examples

{
  a: to_sentencecase('lowercase'),
  b: to_sentencecase('UPPERCASE'),
  c: to_sentencecase('An unusually CASED Sentence. or Two.'),
  d: to_sentencecase('123'),
  e: to_sentencecase(`true`),
  f: to_sentencecase(`null`)
}
{
  "a": "Lowercase",
  "b": "Uppercase",
  "c": "An unusually cased sentence. Or two.",
  "d": "123",
  "e": null,
  "f": null
}