Convert a string from camelcased to underscored and vice versa in PHP

// underscored to upper-camelcase  // "my_test_method" -> "MyTestMethod"  preg_replace('/(?:^|_)(.?)/e',"strtoupper('$1')",$string);  // underscored to lower-camelcase  // "my_test_method" -> "myTestMethod"  preg_replace('/_(.?)/e',"strtoupper('$1')",$string);  // camelcase (lower or upper) to underscored  // "myTestMethod" -> "my_test_method"  // "MyTestMethod" -> "my_test_method"  strtolower(preg_replace('/([^A-Z])([A-Z])/', "$1_$2", $string));