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