• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

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
0
frosty5656
Asked:
frosty5656
1 Solution
 
dr_dedoCommented:
would be nice to post some outcome and how u call it, but for now, try this
$x = new TorrentFile();
$z = array();
$z = $x->parse_file($someFile);
echo $z[0];
 
or 
$x->final_array[0];

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now