|
|
 |
bin2hex (PHP 3>= 3.0.9, PHP 4 , PHP 5) bin2hex --
将二进制数据转换成十六进制表示
描述string bin2hex ( string str)
返回 ASCII 字符串,为参数
str
的十六进制表示。转换使用字节方式,高四位字节优先。
参见 pack() 和 unpack()。
pedram at redhive dot com
01-Feb-2001 09:21
In an attempt to dodge spam bots I've seen people (including myself) hex
encode their email addresses in "mailto" tags. This is the small
chunk of code I wrote to automate the
process:
<?php
function hex_encode ($email_address)
{
$encoded = bin2hex("$email_address");
$encoded = chunk_split($encoded, 2, '%');
$encoded = '%' .
substr($encoded, 0, strlen($encoded) - 1);
return $encoded;
}
?>
so for example:
<a href="mailto:<?=hex_encode("pedram@redhive.com")?>">email
me</a>
would produce the following
address:
%70%65%64%72%61%6d%40%72%65%64%68%69%76%65%2e%63%6f%6d
-pedram
| |