[php]
Nationstates Nationname:
Population (in millions): Leave blank if you want your nation’s population to be used.
[/php]
[php]
Nationstates CalculatorVersion .21
<?php $start = (float) array_sum(explode(' ',microtime()));
$nationname = $_POST[“fname”];
$population = $_POST[“fpop”];
function get_data($nation, $shards = FALSE) {
if($shards != FALSE) {
$file = ‘http://www.nationstates.net/cgi-bin/api.cgi?nation=’ . $nation . ‘&q=’ . $shards;
}
else {
$file = ‘http://www.nationstates.net/cgi-bin/api.cgi?nation=’ . $nation;
}
$xml = simplexml_load_file($file);
return $xml;
}
function display_pop_civilrights($nation) {
$data = get_data($nation, ‘name+population+freedomscores’);
$name = (string) $data->NAME;
if (isset ($population)) {
}
else {
$population = (string) $data->POPULATION;
}
$civil_rights = (string) $data->FREEDOMSCORES->ECONOMY;
$gdp = round(pow($civil_rights, 1.5) * 350 * pow($population, .71) + $population * 100)* 1.5;
$income = round($gdp / $population);
$gdp = number_format($gdp / 1000);
$income = number_format($income);
echo '<p><b>' . $name . '</b><br />Population: ' . $population . '<br />Economic Freedom: ' . $civil_rights . '<br>Avg. Capita Income/Annum ' . $income . ' <br> GNP ' . $gdp . ' billions </p>' ;
}
display_pop_civilrights(‘testlandia’);
display_pop_civilrights($nationname);
// Outputs:
// (bold) Testlandia
// Population: 18245
// Civil Rights: 74
// (bold) Glen-Rhodes
// Population: 7738
// Civil Rights: 77
include ‘bottom.php’;
include ‘linkback.php’;
$end = (float) array_sum(explode(’ ',microtime()));
echo “Processing time: “. sprintf(”%.4f”, ($end-$start))." seconds";
?>