The following snippet converts firstName into first Name
echo preg_replace('/(?<!^)([A-Z])/', ' \\1', 'firstName');