473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

[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 5708
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Justin Koivisto | last post by:
I am replacing a string in a text block that has a literal $ in it, and preg_replace is seeing it as a backreference. Here is what I am using: foreach($price_lists as $list)...
4
by: Alexander Ross | last post by:
I dont think I'll ever understand regular expressions ... I need to do th efollowing and I just don't know where to start: $haystack = "How much wood would a wood chuck chuck if a woodchuck could...
4
by: Sidharta | last post by:
Hi all, how come this doesn't work????? # convert to unix new lines $text = preg_replace("/\r\n/", "\n", $text); # remove extra new lines $text = preg_replace("/\n+/", "\n", $text); is...
1
by: yawnmoth | last post by:
say i have the following script: <? $test = "aaaaa"; print '"' . preg_replace('/.*/','x',$test) . '"<br>'; $test = "\n\n\n\n\n"; print '"' . preg_replace('/.*/','x',$test) . '"'; ?> the...
7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
9
by: Sugapablo | last post by:
I admit, I'm terrible creating reg ex's. I'm trying to create a preg_replace that would remove from a <a href> tag that would replace the target attribute regardless of what the value might be....
1
by: correo | last post by:
Hi all! This: $string = preg_replace('//i', '_', $string); replaces an accented letter with two underscores instead of one, when the submitting page is in UTF8 ($string comes from a GET...
5
by: julianmlp | last post by:
I'm fairly new to regex code, and I'm trying to find a way to replace any text after "///" (three slashes) and before a "\n" character. I've tried with: $filen = preg_replace("///./\n$", "",...
3
by: amygdala | last post by:
Hi there, I'm trying to replace single quoted attributes in HTML tags with double quotes. What I've come up with is this: function replaceSingleQuotesInsideTags( $input ) { $output =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.