Skip to content

Instantly share code, notes, and snippets.

@surdaft
Last active August 7, 2017 11:46
Show Gist options
  • Save surdaft/1b5cd961dbb61873ab2a664609eb6ec1 to your computer and use it in GitHub Desktop.
Save surdaft/1b5cd961dbb61873ab2a664609eb6ec1 to your computer and use it in GitHub Desktop.
Humanize camelCase / PascalCase words
<?php
// Humanize pascalCase / camelCase
// http://stackoverflow.com/questions/4519739#answer-7729790
$regex = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/x';
$example = 'GooglePlus';
$converted = implode(' ', preg_split($regex, $example));
// $converted = 'Google Plus';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment