Two similar API calls PHP optimisation and structure I have the following script that I'm part way through and I'm not happy with it at all, it feels messy:

&lt;?php
class Process {
    public $search = 'http://api.themoviedb.org/2.1/Person.search/en/json/xxx/';
    public $info = 'http://api.themoviedb.org/2.1/Person.getInfo/en/json/xxx/';

    public function returnId($name){
        return $this-&gt;returnJson($this-&gt;search . $name);
    }

    public function returnMovies($id){
        return $this-&gt;returnJson($this-&gt;info . $id);
    }

    public function returnJson($url){
        $raw = file_get_contents($url);
        $json = json_decode($raw, true);
        return $json;
    }
}

$p = new Process();
$first = urlencode($_POST['first']);
$second = urlencode($_POST['second']);

$id = $p-&gt;returnId($first);
$movies = $p-&gt;returnMovies($id[0]['id']);


Now the idea is that two parameters get sent to this script and each of them run through the first API call ($search) and then the ID field is extracted from that results and passed into the $info URL call. The two arrays that come back from returnMovies will be compared with each other and any matches will be popped into another array.

Now, has anyone got any way for this to be better in structure and cleanliness?

It's not finished yet but its a simple script that I'd like to tidy up before I go on.
I'd start firstly by moving your urlencode() into the class... You should assume that everything passed to a method is unclean and therefore act appropriately.

Secondly, I'd give the class a meaningful name - Process isn't entirely descriptive.

Throw some comments in - follow a set standard such as the PHPDoc format, using @param, @return etc. Always handy to have, even if the code doesn't become public or used by others.

Look at your public/private declarations - or lack of. Personally, I'd look to make your $search and $info URLs private, as well as your returnJson() method.

I'd possibly look to use cURL instead of file_get_contents() - due to some server configs disabling that etc. 

Anyway, just a few suggestions!