Skip to content

Instantly share code, notes, and snippets.

Created April 29, 2017 14:12
Show Gist options
  • Save anonymous/aa67d81d5f602cdfa9ff0017a13e9290 to your computer and use it in GitHub Desktop.
Save anonymous/aa67d81d5f602cdfa9ff0017a13e9290 to your computer and use it in GitHub Desktop.
<?php
function getLink($city,$country) {
$city = " ".$city;
$country = " ".$country;
//test.csv is available on https://gist.github.com/anonymous/69693c7fa69284fabc1028fc96c4a2fa
$csvData = file_get_contents("test.csv");
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line);
}
for ($x = 0; $x <= 152; $x++) {
$temp = explode(",", $array[$x][7]);
if (strcmp($city, $temp[1]) == 0 || strcmp($country, $temp[1]) == 0){
return ("https://climate.nasa.gov/images-of-change?id=".$array[$x][0]."#".$array[$x][0]);
break;
}
}
}
//Pass the city as the first parameter and the country as the second parameter
//Example:
echo getLink("Delhi","India");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment