- ltrim: documentation ( source)
- preg_replace: documentation ( source)
- strtolower: documentation ( source)
<?php
function camelCaseToUnderscore($input)
{
return ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $input)), '_');
}
echo camelCaseToUnderscore('CamelCaseForTheWin'), "\n";
echo camelCaseToUnderscore('ACar'), "\n";
echo camelCaseToUnderscore('BuyACar'), "\n";
echo camelCaseToUnderscore('XML'), "\n";
echo camelCaseToUnderscore('SimpleXML'), "\n";