Jump to content


Photo

using a non allowed email character in explode


  • Please log in to reply
2 replies to this topic

#1 horsetags

horsetags
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 August 2006 - 06:20 PM

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.

$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.


Thanks


Paul

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 August 2006 - 06:43 PM

This is incorrect:
$Email_array = explode(_,$Email_raw);
You should add quotes around the underscore:
$Email_array = explode('_', $Email_raw);

If you dont want to use an underscore prehaps use a hash (#) or someother character like ~

To replace the underscores use str_replace:
$str = 'my_username_here@hostname_here.com';

$str = str_replace('_', '#', $str);

echo $str;

WIll return my#username#here@hostname#here.com

#3 horsetags

horsetags
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 August 2006 - 06:53 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users