Help w/ Email Encoder Needed
Posted: Sat Apr 07, 2007 10:09 am
feyd | Please use
Here's the decode function - It's supposed to be able to convert the output from above, back into the email address passed into as the $addr variable
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I have some code below that is 'supposed' to encode a passed in email address. The problem is - if I test the output it's not really encoded, it's the same value I passed in. So for example if I pass in 'billyg@msn.com' - then the output should be some weird encoded string that IS NOT an email address and does not have the '@' character in it.
There's also a decode function, but I can't test it if the encode function isn't working.
[b]PURPOSE[/b] - I will use or run this script on it's own to generate the 'encoded' value. Then I'll store the encoded value as part of a mailer script with a contact form. SO when the users submit the contact form in the php code, the encoded value is stored - not an actual email address that can be harvested by bots. I will have the decode function then and call it encode to decode the encoded string but this will happen as the script executes so that the email address is never stored as a literal string in the mailer script.
I hope this is clear -
[b]PROBLEM[/b] - So this encode_address function doesn't work - what I expect is that the value of the $output variable has the passed in email address encoded into some formatted ASCII characters.
[color=darkblue][size=150]Any ideas how to fix it ??? [/size][b][u]BUT PLEASE[/u][/b] it has to work such that decode function will be able to decode it[/color]
Thanks In Advance!!!
[i] Here's the encode function - I've added some debug code to test the output[/i]Code: Select all
function encode_address($addr)
{
echo "<br><br><br>\nInside the encode function, TO START the addy is " . $addr . "<br><br><br>\n";
$output = "";
for ($i = 0; $i < strlen($addr); $i++) {
$output .= sprintf("&#x%X;", ord($addr{$i}));
}
echo "<br><br><br>\nInside the encode function, TO FINISH the addy is " . $output . "<br><br><br>\n";
return $output;
}Code: Select all
function decode_addr($addr)
{
return preg_replace('/&#x([A-F0-9]{2});/e', ' chr(0x$1); ', $addr);
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]