<?php
set_time_limit
(0);

function 
json_decode_nice($json, $assoc = FALSE){
    
$json = str_replace(array("\n","\r"),"",$json);
    
$json = preg_replace('/([{,])(\s*)([^"]+?)\s*:/','$1"$3":',$json);
    return 
json_decode($json,$assoc);
}

$twfy   = 'http://www.theyworkforyou.com/api/getConstituencies?key=DdjpW4CNDgmDAcPJAMCQZNRm&output=php';
$dump   = file_get_contents($twfy);
$consts = unserialize($dump);

echo 
"<pre>\n";

foreach(
$consts as $const) {
    
$this_const = str_replace(' ', '+', $const['name']);
    
$vfc  = 'http://www.voteforachange.co.uk/index.php/widget/data?cons=' . $this_const;
    
$json = file_get_contents($vfc);
    
$res  = json_decode_nice($json, TRUE);
    echo 
$const['name'] . "\t" . $res['data'][0]['reformParty'] . "\t" . $res['data'][0]['reformCandidate'] . "\n";
}

echo 
"</pre>\n";
?>