468,315 Members | 1,408 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

[newb] preg_replace for an email string


hi,

while i'm not new to php, i'm new to pattern matching and am finding it
rather difficult .. i would like to take a string that's an email address,
and change the '@' with '(at)' and any '.'s with '(dot)'. so for instance,
em***@nospam.com.au would become email(at)nospam(dot)com(dot)au.

many thanks for any pointers
luke

Jul 17 '05 #1
5 5555
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable luke's handwriting:

hi,

while i'm not new to php, i'm new to pattern matching and am finding it
rather difficult .. i would like to take a string that's an email
address, and change the '@' with '(at)' and any '.'s with '(dot)'. so
for instance, em***@nospam.com.au would become
email(at)nospam(dot)com(dot)au.

many thanks for any pointers
luke


Why use preg_replace? It's like firing a cannon on a mosquito. I'd
recommend str_replace - refer to www.php.net for documentation. It will
do exactly what you need.

Cheers
Mike
Jul 17 '05 #2


"Micha³ Wo¼niak" <mikiwoz_remove_this@yahoo_remove_this.co.uk> wrote in
message news:d4**********@213-238-73-81.adsl.inetia.pl...
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable luke's handwriting:


i like to keep my helpers on their toes.

thanks for the tip.

Jul 17 '05 #3
preg_replace(array("/@/","/\./"),array("(at)","(dot)"),"fi********@host.domain.t ld");

Have fun!

Marius

Jul 17 '05 #4

ooh. now that's what i was looking for. many thanks marius!


"sp********************@spamgourmet.com" <ma**************@gmail.com> wrote
in message news:11**********************@z14g2000cwz.googlegr oups.com...
preg_replace(array("/@/","/\./"),array("(at)","(dot)"),"fi********@host.doma
in.tld");
Have fun!

Marius

Jul 17 '05 #5
And to get back to the "cannon on a mosquito" claim

$email = "no****@example.org";
$old = array("@", ".");
$new = array("(at)", "(dot)');

str_replace($old, $new, $email);

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Justin Koivisto | last post: by
4 posts views Thread by Alexander Ross | last post: by
1 post views Thread by yawnmoth | last post: by
7 posts views Thread by Margaret MacDonald | last post: by
9 posts views Thread by Sugapablo | last post: by
1 post views Thread by correo | last post: by
5 posts views Thread by julianmlp | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.