Or here's a function:
function spaces_before_caps($str)
{
$caps = range('A', 'Z');
$new_str = '';
for ($i = 1; $i < strlen($str); $i++) {
if (in_array($str{$i}, $caps) && ($str{$i - 1} != ' ')) {
$new_str .= ' ';
}
$new_str .= $str{$i};
}
return $new_str;
}
Edit: Won't insert before 1st character, or before a character already preceded by a space.