Jump to content


This topic is now archived and is closed to further replies.


using a non allowed email character in explode

Recommended Posts

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'];

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.



Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
Thanks for that

Didn'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,


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.