- preg_replace_callback: documentation ( source)
- strtoupper: documentation ( source)
<?php
$id = 'hierarchical_select';
print preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $id);