cortez creations Posted May 12, 2011 Share Posted May 12, 2011 Hey there. Thinking this should be an easy one but I can only seem to find info on the string replace function. What I'm trying to do is strip everything after the @ from an email variable. So for example $mail variable comes in as [email protected] How would I strip the variable to only contain me and remove the @gmail.com I'll keep searching for the answer myself but if anyone can throw me a bone it's be appreciated. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/236266-strip-part-of-string-variable/ Share on other sites More sharing options...
fugix Posted May 12, 2011 Share Posted May 12, 2011 $string = "[email protected]"; $strpos = strpos($string, '@') $substr = substr($string, 0, $strpos); Quote Link to comment https://forums.phpfreaks.com/topic/236266-strip-part-of-string-variable/#findComment-1214715 Share on other sites More sharing options...
.josh Posted May 12, 2011 Share Posted May 12, 2011 If you are using php 5.3+ You can just use strstr $user = strstr($email, '@', true); Quote Link to comment https://forums.phpfreaks.com/topic/236266-strip-part-of-string-variable/#findComment-1214718 Share on other sites More sharing options...
cortez creations Posted May 12, 2011 Author Share Posted May 12, 2011 Excellent thanks to both of you. Always great to add a few more tools to the toolbox! Quote Link to comment https://forums.phpfreaks.com/topic/236266-strip-part-of-string-variable/#findComment-1214726 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.