|
Posted by David Gillen on 01/04/07 14:49
schwooba@gmail.com said:
> Is there a simple way to remove the last part of an email address using
> PHP. I want to remove the @ symbol and everything to the right of it.
> Any ideas?
>
> Example:
>
> thomas@xyz.com
>
> should be:
>
Use substr[1] to get from the start of the string to the point you want.
The point you want is @ , indentified by strpos[2].
[1] http://www.php.net/substr
[2] http://www.php.net/strpos
So
$name = substr($email, 0, strpos($email, '@'));
should get you fairly close to what you want. Might need to increment or
decrement the result of strpos, I can't recall, to avoid getting the @ symbol
or get the last char of the name.
Or you could
$array = explode('@', $email); // Ka-BOOM!
$name = $array[0];
D.
--
Navigation:
[Reply to this message]
|