Custom implementation of bin2hex
<p>While looking over some code, I found a function that seems to do exactly what <a href="http://de.php.net/manual/en/function.bin2hex.php" rel="nofollow"><code>bin2hex</code></a> does. I tested on large sets of randomly generated input and they were identical. What I would like to know is if anyone can see any difference between them. Or maybe someone can give me some information about the implementation of <code>bin2hex</code>.</p>

<p>Here is the function I was telling you about:</p>

<pre><code>function strToHex($str){
    $result='';
    $map = array(
        '0' =&gt; '00',
        '1' =&gt; '01',
        '2' =&gt; '02',
        '3' =&gt; '03',
        '4' =&gt; '04',
        '5' =&gt; '05',
        '6' =&gt; '06',
        '7' =&gt; '07',
        '8' =&gt; '08',
        '9' =&gt; '09',
        'a' =&gt; '0a',
        'b' =&gt; '0b',
        'c' =&gt; '0c',
        'd' =&gt; '0d',
        'e' =&gt; '0e',
        'f' =&gt; '0f'
    );

    for ($i=0; $i &lt; strlen($str); $i++){
        $tmp = dechex(ord($str[$i]));
        if(isset( $map[$tmp]))
            $tmp = $map[$tmp];
        $result .= $tmp;
    }

    return $result;
}
</code></pre>

<p>Thank you,<br>
Alin</p>
