goodScotchWhiskey to GOOD_SCOTCH_WHISKEY
Yesturday I wrote some PHP snippet to convert camel-style names (e.g. goodScotchWhiskey) to upper-case-style constant names (e.g. GOOD_SCOTCH_WHISKEY).
function _camelToUpper($name)
{
return strtoupper(join('_', array_slice(
preg_split('{(?=[A-Z])}s', ucfirst($name)), 1
)));
}

0 comments:
Post a Comment