I want to replace a set of binary charators in some files (1-2MB sized) using php.
I tried below functions. but they got overflow when loading file to variable.
Code: Select all
    function gethex()
    {
    $file = 'source.mp3';
        $handle = fopen($file, 'r') or die('permission?');
        
            while(!feof($handle))
            {
                foreach(unpack('C*',fgets($handle)) as $dec)
                {
                    $tmp = dechex($dec);
                    $this->hex[] .= strtoupper(str_repeat('0',2-strlen($tmp)).$tmp);    
                }
            }
        
        return join($this->hex);
    }
    
//****************************************
    function writehex($hexcode)
    {
        $file = 'test.mp3';
        foreach(str_split($hexcode,2) as $hex)
        {
            $tmp .= pack('C*', hexdec($hex));
        }
        
            $handle = fopen($file, 'w+') or die('permission?');
            fwrite($handle, $tmp);
        
    } Please tell me another way to do it.
Thankz.
[ Post made via Mobile Device ]





