472,805 Members | 1,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 5693
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 =...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.