<?php

function camelToUS1($string, $us = "-")
{
    // insert hyphen between any letter and the beginning of a numeric chain
    $string = preg_replace('/([a-z]+)([0-9]+)/i', '$1'.$us.'$2', $string);
    // insert hyphen between any lower-to-upper-case letter chain
    $string = preg_replace('/([a-z]+)([A-Z]+)/', '$1'.$us.'$2', $string);
    // insert hyphen between the end of a numeric chain and the beginning of an alpha chain
    $string = preg_replace('/([0-9]+)([a-z]+)/i', '$1'.$us.'$2', $string);

    // Lowercase
    $string = strtolower($string);

    return $string;
}
function camelToUS2($string, $us = "-") {
    return strtolower(preg_replace(
    	'/(?<=\d)(?=[A-Za-z])|(?<=[A-Za-z])(?=\d)|(?<=[a-z])(?=[A-Z])/', $us, $string));
}
function camelToUS3($string, $us = "-") {
    return strtolower(preg_replace('/(?<!^)[A-Z]+|(?<!^|\d)[\d]+/', $us.'$0', $string));
}

$test_values = [
    'foo'       => 'foo',
    'fooBar'    => 'foo-bar',
    'foo123'    => 'foo-123',
    '123Foo'    => '123-foo',
    'fooBar123' => 'foo-bar-123',
    'foo123Bar' => 'foo-123-bar',
    'foo123bar' => 'foo-123-bar',
    '123FooBar' => '123-foo-bar',
];

echo "OP:\n";
foreach ( $test_values as $key => $val ) {
   echo "$key: " . camelToUS1($key) .  " => " . (camelToUS1($key) == $val) . "\n";
}
echo "\nanubhava:\n";
foreach ( $test_values as $key => $val ) {
   echo "$key: " . camelToUS2($key) .  " => " . (camelToUS2($key) == $val) . "\n";
}
echo "\nAdrien Leber:\n";
foreach ( $test_values as $key => $val ) {
   echo "$key: " . camelToUS3($key) .  " => " . (camelToUS3($key) == $val) . "\n";
}

?>