-1
<?php
    $str = "[email protected]";
    $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

2 Answers2

0

You can use explode()

$str = "[email protected]";

$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