Skip to content

Instantly share code, notes, and snippets.

@murilozilli
Last active February 14, 2020 02:35
Show Gist options
  • Save murilozilli/63c7b4885340da047c19633c1cad603e to your computer and use it in GitHub Desktop.
Save murilozilli/63c7b4885340da047c19633c1cad603e to your computer and use it in GitHub Desktop.
CamelCase to Snake_case
<?php
function camelToSnake($input)
{
if (preg_match('/[A-Z]/', $input) === 0) {
return $input;
}
$pattern = '/([a-z])([A-Z])/';
$r = strtolower(preg_replace_callback($pattern, function ($a) {
return $a[1] ."_". strtolower($a[2]);
}, $input));
return $r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment