Skip to content

Instantly share code, notes, and snippets.

@Traineratwot
Created March 3, 2022 13:33
Show Gist options
  • Save Traineratwot/1406decab7b3d7bb8a304660fa320336 to your computer and use it in GitHub Desktop.
Save Traineratwot/1406decab7b3d7bb8a304660fa320336 to your computer and use it in GitHub Desktop.
<?php
function name2class($name)
{
$name = preg_replace("@([A-Z])@","_$1",$name);
$name = strtr($name, [
'\\' => '_',
'/' => '_',
'-' => '_',
' ' => '_',
'*' => '_',
'.' => '_',
'+' => '_',
]);
$n = explode("_", $name);
$n2 = [];
foreach ($n as $value) {
$n2[] = ucfirst(mb_strtolower($value));
}
$class = ucfirst(implode('', $n2));
return $class;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment