I need to get the user name from email. I was about to use SPLIT but noticed that is going to be deprecated shortly (for me).
$em = split("@",$email); $user = $em[0];
What's the next best alternative?
Hmm... I think I'm going to do the same with explode, unless there's a better option.
This is the example from strstr() function at php.net 😃
<?php $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com $user = strstr($email, '@', true); // As of PHP 5.3.0 echo $user; // prints name ?>
Yeah, my PHP version is below 5.3.0...
How about explode()?
$user = array_shift(explode('@', $text));
Yes, I used explode but without array_shift. Why do I need it?
It's just a quick way to grab the first element of the resulting array, assuming you don't need to use the array any more. Not required at all.
It actually works great, thanks for the recommendation. I am working with somewhat finicky script that does not like a lot of code that I put. This one worked great. I'm keeping it.
I need to get user id from mail. That we also need to keep proper records of these things. Hence I want to get all that. weight loss products colon cleanser vigrx