phpsubstringtext-extraction

How to get a substring from string through PHP?


I want to change the displayed username from abcd@somedomain.com to only abcd. For this, I should clip the part starting from @.

I can do this very easily through variablename.substring() function in Java or C#, but I m not aware with the syntax of PHP.

Suppose I'm having variable like:

$username = "abcd@somedomain.com";
$username = {some string manipultion function}
echo $username; // abcd

Solution

  • Try this:

    $username = substr($username, 0, strpos($username, '@'));