
preg_replace('/^webmail|gw|mail|otherstring\./i','', $vdomain); before the regex ends here - |^(webmail| -as you are using pipe as a delimiter for the whole regex you shouldn't need parenthesis as this is used for capturing and you are only replacing (not tested) On 11/04/2010 01:00 PM, Odhiambo Washington wrote:
Hello world,
I am looking at a certain function in php, from the IMP mail reader (Horde Groupware). I have played a bit with it, but I hate the idea of having several lines of:
$vdomain = preg_replace('|^STRING\.|i', '', $vdomain);
<CUT>
if (!function_exists('_imp_hook_vinfo')) { function _imp_hook_vinfo($type = 'username') { $vdomain = getenv('HTTP_HOST'); $vdomain = preg_replace('|^webmail\.|i', '', $vdomain); $vdomain = preg_replace('|^gw\.|i', '', $vdomain); $vdomain = preg_replace('|^mail\.|i', '', $vdomain); $vdomain = preg_replace('|^(webmail|gw|mail|otherstring)\.|i','', $vdomain); $vdomain = String::lower($vdomain);
if ($type == 'username') { return preg_replace('|\.|', '.', $_SESSION['imp']['user'] . '@' . $vdomain); } elseif ($type == 'vdomain') { return $vdomain; } else { return PEAR::raiseError('invalid type: ' . $type); } } } </CUT>
Now, instead of having several lines to match and replace a certain string with an empty string, I am thinking a single line regex would do, and it should, no?? I have tried the following:
$vdomain = preg_replace('|^(webmail|gw|mail|otherstring)\.|i','', $vdomain);
But I end up with an error: Unknown modifier 'g' in *hooks.php.*
Is it because I am using mixed up string separator?