aebstract Posted March 21, 2008 Share Posted March 21, 2008 I'm trying to figure out how to remove the @ and everything after it in an email address. So test@tester.com would end up as just test. I dunno if I'm in the right direction or not, possibly an easy way to do this and I'm going way out of the way.. str_replace (^[@]$,,$email); Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 easier is <?php $email = "Email@test.com"; $sub_email = substr($email,0,strpos($email,"@")-1); echo $sub_email; ?> Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 21, 2008 Author Share Posted March 21, 2008 Can you explain what its doing, like why it works so I understand for future I think the -1 is taking a character off before the @ sign Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 reaad substr and strpos Quote Link to comment Share on other sites More sharing options...
Barand Posted March 21, 2008 Share Posted March 21, 2008 you think correctly. strpos() above returns 5 (counting from 0) so you want the first 5 characters, not the first 4. [pre] e m a i l @ 0 1 2 3 4 5 Cooldude - good advice Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 21, 2008 Share Posted March 21, 2008 You can also use explode(): <?php $email = 'tester@example.com'; list($sub_email) = explode('@',$email); echo $sub_email; ?> Ken Quote Link to comment 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.