-1
<?php
    $str = "xyz@gmail.com";
    $username = strstr($str, '@', true);
    echo $username;
?>

I want to remove sender name before @ tag and output should be @gmail.com. Now, It shows me xyz output which I don't want. So, How can I do this? Please help me. I want to output @gmail.com.

steave
  • 135
  • 2
  • 15
  • 1
    Just remove the `true` parameter to [`strstr`](http://php.net/manual/en/function.strstr.php) and it will give you the text *after* (and including) the delimiter – Nick Feb 20 '19 at 11:04
  • This is also fun, but not worthy of an answer: `strrev(strtok(strrev('xyz@gmail.com'), '@'));` – naththedeveloper Feb 20 '19 at 11:48

2 Answers2

0

You can use explode()

$str = "xyz@gmail.com";

$tld = explode("@", $str)[1]; // gmail.com
B001ᛦ
  • 2,036
  • 6
  • 23
  • 31
0

You could replace the part before the @-character with an empty string:

$username = preg_replace('/^[^@]+/', '', $str);
Flinsch
  • 4,296
  • 1
  • 20
  • 29