-1

I have an html code which displays user email from php. However i want to trim this part @gmail.com And display the left part.

Currently I tried this code which is not working.

<p id="p1"><?php
 $str = ""
 echo $str . "<br>";
 echo trim($str,"@gmail.com");
 echo htmlspecialchars($_SESSION["username"]);
?></p>

What is the best way to correct it?

For example the email from php database is name1@gmail.com, i want to remove @gmail.com and display only name1

John Conde
  • 217,595
  • 99
  • 455
  • 496
Elitte
  • 21
  • 5

1 Answers1

2

trim() is not the best choice. Simply split email by @:

$expl = explode('@', $str);
echo $expl[0];
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141