How to get master-at-home from masterAtHome ?
|
2 answers
You can do the following:
<?php echo preg_replace_callback( '/(?<!^)([AZ])/', function($match) { return '-'.strtolower($match[1]); }, 'masterAtHome'); |
This is a typical task of converting Camel Case strings to Snake Case (with minuses instead of underscores).
Here is one of the easiest conversion options:
echo strtolower(preg_replace("/(?!^)([AZ])/", '-$1', 'masterAtHome')); In the example above, a group of characters (?!^) used to ignore a capital letter if it goes first in the line.
A working example on Ideone .
|