Example 1 — Split an Email Address
Get the part after and before the @ sign.
<?php
$email = "[email protected]";
echo strstr($email, "@"), PHP_EOL;
echo strstr($email, "@", true), PHP_EOL; How It Works
- Search for "@". strstr() finds the first match.
- Default result. It returns everything from
@to the end. - Use before_needle. Passing
trueflips the result. - Get the username. The second call returns
"user".

