Jump to content

Foreach loop with the array of a public function


mofle

Recommended Posts

Hi, i need to do a loop of the array of this function found in the WebUI API:

public function getTorrents()

 

 

WebUI API: http://pastebin.com/m76205d0b

 

 

I have this one, but it doesn't work.

 

$utorrent = new uTorrent();
$utorrent->host = $_SESSION['host'];
$utorrent->user = $_SESSION["user"];
$utorrent->pass = $_SESSION["pass"];
$torrents = $utorrent->getTorrents();

foreach($torrents as $torrent) {
    echo $torrent[uTORRENT_TORRENT_NAME]."\n";
}

 

How do i use the "public function getTorrents()" to get the array into a foreach loop?

 

I really appreciate your help ;)

 

 

It seems like it's returning JSON. You can use json_decode() to turn it into an array.

 

 

Yes, take a look at this bit of the WebUI at the bottom:

it gets and decodes the json, what i need i a method to get the array from "public function getTorrents()" and get it into a foreach loop.

 

Do you think you can help me with that?

 

 

 

// performs request
    private function makeRequest($action, $decode = true, $options = array()) {
        $ch = curl_init();
        curl_setopt_array($ch, $options);
        curl_setopt($ch, CURLOPT_URL, "http://".$this->host."/gui/".$action);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERPWD, $this->user.":".$this->pass);
        $req = curl_exec($ch);
        curl_close($ch);

        return ($decode ? json_decode($req, true) : $req);
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.