超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<addslasheschop>
Last updated: Fri, 22 Jun 2007

bin2hex

(PHP 3>= 3.0.9, PHP 4 , PHP 5)

bin2hex --  将二进制数据转换成十六进制表示

描述

string bin2hex ( string str)

返回 ASCII 字符串,为参数 str 的十六进制表示。转换使用字节方式,高四位字节优先。

参见 pack()unpack()




add a note add a note User Contributed Notes
bin2hex
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:&lt;?=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

<addslasheschop>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22