php preg_match, how to switch values
Please help with this little issue if you could.
I would like to search a string, if a match is made, I'd like to change the value to something else.
eg.开发者_如何学运维
if (preg_match("gmail",$email)) {
// code needed to switch "gmail" for "googlemail"
}
This is needed because my mail server won't accept an email address in 'gmail.com' format.
Thanks in advance. Shane
if you don't need regular expressions just use str_replace. No need to test either, just replace it.
str_replace( '@gmail.com', '@googlemail.com', $email );
Just so it doesn't match something like mygmail@gmail.com
:
$email = preg_replace('/(.+)gmail(\..+)$/', '$1googlemail$2', $email);
Use preg_replace
:
preg_replace("gmail", "googlemail", $email);
精彩评论