i’m working on class names and i need to check if there is any upper camel case name and break it this way:
"UserManagement" becomes "user-management"
or
"SiteContentManagement" becomes "site-content-management"
after extensive search i only found various use of ucfirst, strtolower,strtoupper, ucword and i can’t see how to use them to suit my needs any ideas?
thanks for reading 😉
You can use
preg_replaceto replace any instance of a lowercase letter followed with an uppercase with your lower-dash-lower variant:Then followed by a
strtolower()to take care of any remaining uppercase letters:The full function here:
To explain the regular expression used:
As for the replacement string