/    Sign up×
Community /Pin to ProfileBookmark

striping email address from the string

Ok another strip question :rolleyes:
how do I strip all emails from the string? or actually what the email partent?

here is the code I think should work but I dont know how to write the paterns 🙁

[code=php]
$pattern = array(“”);

$text = “my string [email protected] and some other text”;
$replace = ‘ ‘;
$text = preg_replace($pattern, $replace, $text);
print $text;

[/code]

Any help? Thanks!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@alexusauthorJan 16.2007 — well ok my own unswer:
[code=php]
$string="hello my email is [email protected]";

$string = preg_replace('#(.*)@(.*).(.*)#', ' ', $string);
print $string;
[/code]
Copy linkTweet thisAlerts:
@NogDogJan 17.2007 — [code=php]
function strip_emails($text) {
$qtext = '[^\x0d\x22\x5c\x80-\xff]';
$dtext = '[^\x0d\x5b-\x5d\x80-\xff]';
$atom = '[^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c'.
'\x3e\x40\x5b-\x5d\x7f-\xff]+';
$quoted_pair = '\x5c\x00-\x7f';
$domain_literal = "\x5b($dtext|$quoted_pair)*\x5d";
$quoted_string = "\x22($qtext|$quoted_pair)*\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\x2e$sub_domain)*";
$local_part = "$word(\x2e$word)*";
$addr_spec = "$local_part\x40$domain";
return preg_replace("!b$addr_specb!", '', $text);
}
[/code]
Copy linkTweet thisAlerts:
@alexusauthorJan 17.2007 — lol that kinda complex, but I see it also assumes posuble subdomains :-)

thanks, I will use this one
×

Success!

Help @alexus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...