Last active
July 5, 2017 15:35
-
-
Save bubba-h57/adddc27ebb6f951c20bc0da08ad3f09d to your computer and use it in GitHub Desktop.
Convert studly, traditional snake, and kebob case strings into a non-breakable snake case string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function non breakable snake case($value, $delimiter = ' ') | |
{ | |
$value = ucwords(str_replace(['-', '_'], ' ', $value)); | |
if (! ctype_lower($value)) { | |
$value = preg_replace('/\s+/u', '', $value); | |
$value = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value), 'UTF-8'); | |
} | |
return $value; | |
} | |
$studly = non breakable snake case('thisIsATest'); | |
$snake = non breakable snake case('this_Is_A_Test'); | |
$kebob = non breakable snake case('This-is-a-test'); | |
printf("Studly:\t%s\nSnake:\t%s\nKebob:\t%s\n", $studly, $snake, $kebob); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment