Created
April 29, 2017 14:12
-
-
Save anonymous/aa67d81d5f602cdfa9ff0017a13e9290 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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