Link to home
Start Free TrialLog in
Avatar of frosty5656
frosty5656

asked on

Class and Array Help Needed

I am new to PHP and am having a very hard time trying to use a class I've downloaded.

 It seems like a simple class that breaks down information into arrays. However, I have no idea on how to access the arrays the class produces. I can use the var_dump function and see the arrays but after many many many hours of trying I can't access them at all. I have no idea of how to access any of the info the class produces.

Here is the class

============== Class Code =====================================================


        
class TorrentFile {
    var $index;
    var $source;
    var $final_array;


    function handler() {
        $char = $this->source[$this->index];

        if (is_numeric($char)) return $this->handler_string();
        if ($char == 'i') {
            ++$this->index;
            return $this->handler_int();
        }
        if ($char=='l') {
            ++$this->index;
            return $this->handler_list();
        }
        if ($char=='d') {
            ++$this->index;
            return $this->handler_dictonary();
        }

        die("MAIN HANDLER: UNEXPECTED CHAR (position: $this->index): ".$char);
    }


    function handler_int() {
        $current_char='';
        $number = "";

        while (($current_char = $this->source[$this->index]) != 'e') {
            ++$this->index;
            $number .= $current_char;
        }

        ++$this->index;

        return (int) $number;
    }



    function handler_string(){
        $size ="";
        while($this->source[$this->index] != ':') {
            $size .= $this->source[$this->index];
            ++$this->index;
        }

        $i = ++$this->index;
        $this->index += $size;

        $x= substr($this->source, $i, $size);

        return $x;
    }

    function handler_list() {
        $return_list = array();

        while ($this->source[$this->index] != 'e') {
            $this->index1 = $this->index;
            $return_list[] = $this->handler();
            if ($this->index1 == $this->index) die("INFINITE LOOP IN THE LIST");
        }
        ++$this->index;

        return $return_list;
    }

    function handler_dictonary() {
        $return_dict = array();

        while ($this->source[$this->index] != 'e') {
            $this->index1 = $this->index;
            $return_dict[$this->handler_string()] = $this->handler();
            if ($this->index1 == $this->index) die("INFINITE LOOP IN THE DICTONARY");
        }
        ++$this->index;

        return $return_dict;
    }


    function parse_file($filename) {
        $this->source = $filename;

        $this->index = 0;
        $filesize = strlen($this->source);

        $this->final_array=array();

        while($this->index<$filesize) {
            $this->index1 = $this->index;
            $this->final_array[] =$this->handler();
            if ($this->index1 == $this->index) die("INFINITE LOOP IN THE ROOT LIST");
        }

        $this->source = '';
        return $this->final_array;
    }
}

====================== End of Class ===========================================

I can pass a file to the class to break down the info into great data, but how in the world do you access the info so you can actually use it???

 I can't find any help files on the net that can simply explain this for me.

Please Help
ASKER CERTIFIED SOLUTION
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial