Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Show only domain from blacklist_email

Asked Modified Viewed 3,247 times
S
smokeman
S
  • Veteran Member, joined since
  • Contributed 920 posts on the community forums.
  • Started 79 threads in the forums
  • Started this discussions
asked
Veteran Member

Hi folks.

How can I show only the domian name from the field $data['blacklist_email'] ?

I was thinking on something about:
$domain =  preg_replace($data['blacklist_email'],'^.*@');

- but I can't figure out how exactly Im doing that..

Anyone having some input ?

Regards,
Smokeman.
0 replies

5 posts

M
MarcusG
M
Ex Senior Dev.
  • Member, joined since
  • Contributed 182 posts on the community forums.
  • Started 5 threads in the forums
answered
Member

Try this:


<?php
$email  = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // result: @example.com

$user = strstr($email, '@', true); // since PHP 5.3.0
echo $user; // result: name
?>


http://php.net/manual/de/function.strstr.php
0 replies
S
smokeman
S
  • Veteran Member, joined since
  • Contributed 920 posts on the community forums.
  • Started 79 threads in the forums
  • Started this discussions
answered
Veteran Member

AFter some more reading/serching I found out that this does the job:
$exp_domain = explode('@', $data['blacklist_email']);
$domain = $exp_domain[1];

- but then an error showing up in the errorlog: Undefined offset: 1

I don't know for sure how to use the code you provided.. ?
0 replies
P
PolarFox
P
  • Veteran Member, joined since
  • Contributed 1,633 posts on the community forums.
  • Started 29 threads in the forums
answered
Veteran Member

If you already have only domain instead of full e@mail (mail,com instead => some@mail,com) , this error appears.

You can check with:
count($exp_domain)// must be at least 2
, or
isset($exp_domain[1]) //must be true
0 replies
R
ronald1985
R
  • Newbie, joined since
  • Contributed 5 posts on the community forums.
answered
Newbie

$exp_domain = explode('@', $data['blacklist_email']);
$domain = (isset($exp_domain[1]) ? $exp_domain[1] : "");
0 replies
S
smokeman
S
  • Veteran Member, joined since
  • Contributed 920 posts on the community forums.
  • Started 79 threads in the forums
  • Started this discussions
answered
Veteran Member

Thx Polarfox & ronald85. That worked fine. :G
0 replies

Category Forum

General Discussion

Labels

None yet

Statistics

  • Views 0 views
  • Posts 5 posts
  • Votes 0 votes
  • Topic users 4 members

4 participants

S
S
  • Veteran Member, joined since
  • Contributed 920 posts on the community forums.
  • Started 79 threads in the forums
  • Started this discussions
P
P
  • Veteran Member, joined since
  • Contributed 1,633 posts on the community forums.
  • Started 29 threads in the forums
M
M
Ex Senior Dev.
  • Member, joined since
  • Contributed 182 posts on the community forums.
  • Started 5 threads in the forums
R
R
  • Newbie, joined since
  • Contributed 5 posts on the community forums.

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet