note 90868 modified in function.str-replace by danbrown
| From: | danbrown@php.net | Date: | Wed, 13 May 2009 17:27:39 +0000 |
| Subject: | note 90868 modified in function.str-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154565@lists.php.net to get a copy of this message | ||
I create a little function to transform "User@example.net" [to] "user AT example DOT
net" and conversely.
<?php
function code_mail($email) {
if(preg_match('
^.+@.+\..{1,5}$', $email)) { //email format
$email = str_replace('.', ' DOT ', $email); //replace . by dot
$email = str_replace('@', ' AT ', $email); //replace @ by at
return $email;
}
else { //not email format
return false;
}
}
function decode_mail($email) { //on décode...
$email = str_replace(' DOT ', '.', $email); //replace dot by .
$email = str_replace(' AT ', '@', $email); //replace at by @
return $email;
}
?>
--was--
I create a little function to transform (to example) "User@example.net" in "user AT
example DOT net" and conversely.
<?php
function code_mail($email) {
if(preg_match('^.+@.+\..{1,5}$', $email)) { //email format
$email = str_replace('.', ' DOT ', $email); //replace . by dot
$email = str_replace('@', ' AT ', $email); //replace @ by at
return $email;
}
else { //not email format
return false;
}
}
function decode_mail($email) { //on décode...
$email = str_replace(' DOT ', '.', $email); //replace dot by .
$email = str_replace(' AT ', '@', $email); //replace at by @
return $email;
}
?>
http://php.net/manual/en/function.str-replace.php