Jump to content

using a non allowed email character in explode


horsetags

Recommended Posts

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.


Thanks


Paul
Link to comment
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
Link to comment
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,

Paul
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.