What is it doing instead? Anything?
What the code you've given does (just checking to see if it's what's intended):
-
Does the line $address end with 'address1'?
-
If it does, replace 'address1' (whether in upper or lower case) with 'address2' and echo the result.
Note that this doesn't change $address at all.
One thing that should be noted: '.' has a special meaning in regular expressions, so something will have to be done about these in the email address.
$address1=preg_quote('whatever address1 is supposed to be'); // preg_quote() makes sure that '.' is
$address2=preg_quote('whatever address2 is supposed to be'); // handled properly.
if(substr($address,-strlen($address1))==$address1)
{
echo preg_replace("/$address1/i",$address2,$address);
}
Will have the same effect and do without the ereg_* functions.
If $address1 and $address2 are always in lower case and you don't need to worry about uppercase versions, then the preg_replace can go as well:
echo str_replace($address1,$address2,$address);
and the calls to preg_quote() can be dropped.
If you know all this all ready, then whatever is not working is not in what you've given.