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 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); 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); 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! 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
Archived
This topic is now archived and is closed to further replies.