How can I replace a set of words that look like:
SomeText
to
Some_Text
?
The simplest way to do this is with a regular expression replacement.
For example:
substr(preg_replace('/([A-Z])/', '_$1', 'SomeText'),1);
The substr call there is to remove a leading '_'