Skip to content

Instantly share code, notes, and snippets.

@wrabit
Last active March 18, 2020 18:44
Show Gist options
  • Save wrabit/ce08834fb1adc0b4fbb5a011ab5fbc87 to your computer and use it in GitHub Desktop.
Save wrabit/ce08834fb1adc0b4fbb5a011ab5fbc87 to your computer and use it in GitHub Desktop.
PHP: Camel case to title case function
if (!function_exists('camel_to_title')) {
function camel_to_title($string = '')
{
// let's create spaces
$intermediate = preg_replace('/(?!^)([[:upper:]][[:lower:]]+)/', ' $0', $string);
// now upper case words
return mb_convert_case($intermediate, MB_CASE_TITLE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment