bin2hex and the other way around

bin2hex ( ) = php-Funktion

Hex to ASCII:

   function hex2asc ($strMail) {
     for ($i=0; $i<strlen($strMail)/2; $i++) {
        $asc = '';
        $asc.=chr(base_convert(substr($strMail,$i*2,2),16,10));
     }
     return $asc;
   }

to unicode:

   function uni_encode ($strMail) {
      $encoded = bin2hex("$strMail");
      $encoded = chunk_split($encoded, 2, '%');
      $encoded = '%' . substr($encoded, 0, strlen($encoded) - 1);
      return $encoded;    
   }

to hex :

   function hex_encode($strMail)
   {
     $ret_string = '';
     $len = strlen($strMail);
     for ($x=0; $x<$len; $x++){
         $ord=ord(substr($strMail, $x, 1));
         $ret_string .= "&#$ord;";
     }
     return $ret_string;
   }

$strEmail = "aa@bb.ch";


bin2hex("hallo") > 68616c6c6f
hex2asc("68616c6c6f") > hallo
   
bin2hex("mailto:aa@bb.cc") > 6d61696c746f3a61614062622e6363
ds. mit den a-tags (mailto funkt aber nicht!) > 6d61696c746f3a61614062622e6363
   
hex2asc('6d61696c746f3a61614062622e636363') > email - OK
obige Zeile = <a href="<?php echo hex2asc('6d61696c746f3a61614062622e636363'); ?>">email</a>
   
Uni-Encoder:
<a href="mailto:" . uni_encode($strEmail) .">email<a/>

> email - OK
HTML-Output:
<a href="mailto:%73%65%6e%73%65%40%76%74%78%6e%65%74%2e%63%68">email</a>
Hex-Encoder:
<a href="mailto:". hex_encode($strEmail) .">". hex_encode($strEmail) ."<a/>

> aa@bb.ch - OK
HTML-Output:
<a href="mailto:&#115;&#101;& ...   ... &#120;&#110;&#101;&#116;&#46;&#99;&#104;</a>