如何在php5.3中做hex2bin

hex2bin() function is supported after php5.4. It is not available in php5.3. How can I do hex2bin in php3 ?

 echo hex2bin("48656c6c6f20576f726c6421");

Just use

 $foo = pack("H*" ,"48656c6c6f20576f726c6421");
 echo $foo

In PHP 5.3 you can use pack

docs

Pack given arguments into a binary string according to format.

string pack ( string $format [, mixed $args [, mixed $... ]] )

So you're looking for:

$result = pack('H*', '48656c6c6f20576f726c6421');

hex2bin is available with PHP Version >= 5.4.0 - is your PHP version up 2 date?

Below (copied from php.net) is a solution if your version can not be updated: https://stackoverflow.com/a/17963343/6775488

<?php 
        function hextobin($hexstr) 
    { 
        $n = strlen($hexstr); 
        $sbin="";   
        $i=0; 
        while($i<$n) 
        {       
            $a =substr($hexstr,$i,2);           
            $c = pack("H*",$a); 
            if ($i==0){$sbin=$c;} 
            else {$sbin.=$c;} 
            $i+=2; 
        } 
        return $sbin; 
    } 
?>