horsetags Posted August 28, 2006 Share Posted August 28, 2006 Hi,i have a peice of code that works great as long as someone does not have an underscore in their email address.I attach the date and time to the email so that my login required site does not recognise the email on subsequent visits which allows guests to buy stuff.[code]$guest_pass = $row['pass']; if ($guest_pass == "guestpass") { $Email_raw = $row['Email']; $Email_array = explode(_,$Email_raw); $Email = $Email_array[1]; } else { $Email = $row['Email']; }[/code]I need to replace the underscore with something that is not used in an email address and will go into a database ok.i have searched the web, but cannot find any info on this (strangely, but could well be me)I am not a profficient coder and can do basic stuff, so would be grateful if someone could tell me what would work instead of an underscore.ThanksPaul Quote Link to comment https://forums.phpfreaks.com/topic/18925-using-a-non-allowed-email-character-in-explode/ Share on other sites More sharing options...
wildteen88 Posted August 28, 2006 Share Posted August 28, 2006 This is incorrect:[code]$Email_array = explode(_,$Email_raw);[/code]You should add quotes around the underscore:[code]$Email_array = explode('_', $Email_raw);[/code]If you dont want to use an underscore prehaps use a hash (#) or someother character like ~To replace the underscores use str_replace:[code=php:0]$str = 'my_username_here@hostname_here.com';$str = str_replace('_', '#', $str);echo $str;[/code]WIll return my#username#here@hostname#here.com Quote Link to comment https://forums.phpfreaks.com/topic/18925-using-a-non-allowed-email-character-in-explode/#findComment-81753 Share on other sites More sharing options...
horsetags Posted August 28, 2006 Author Share Posted August 28, 2006 Thanks for thatDidn't know about the quotes, but i will use the hash and as i have the code that supplies the '_' i will change it for a hash and just modify the email addresses that already have an underscore prefix.Thanks for the other info as it is all good learning (if my brain can hold it all!)Thanks again,Paul Quote Link to comment https://forums.phpfreaks.com/topic/18925-using-a-non-allowed-email-character-in-explode/#findComment-81759 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.