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 [email protected] 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); Link to comment https://forums.phpfreaks.com/topic/97225-is-this-close-replacing/ Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 easier is <?php $email = "[email protected]"; $sub_email = substr($email,0,strpos($email,"@")-1); echo $sub_email; ?> Link to comment https://forums.phpfreaks.com/topic/97225-is-this-close-replacing/#findComment-497474 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 Link to comment https://forums.phpfreaks.com/topic/97225-is-this-close-replacing/#findComment-497476 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 reaad substr and strpos Link to comment https://forums.phpfreaks.com/topic/97225-is-this-close-replacing/#findComment-497484 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 Link to comment https://forums.phpfreaks.com/topic/97225-is-this-close-replacing/#findComment-497489 Share on other sites More sharing options...
kenrbnsn Posted March 21, 2008 Share Posted March 21, 2008 You can also use explode(): <?php $email = '[email protected]'; list($sub_email) = explode('@',$email); echo $sub_email; ?> Ken Link to comment https://forums.phpfreaks.com/topic/97225-is-this-close-replacing/#findComment-497492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.