Adolfsen,
I highly recommend AGAINST using CSV in this fashion, especially since the number of Canadian Postal Codes is over 1M, and has 7.2M TOTAL possible postal codes.
The US Zip codes is still very very high, and even more so with the 5+4 zip codes.
This Function Below will find the text input ($text_input) and return an array with the tnire line of the CSV file. Keep in mind #0 is the first one in the list, as PHP starts with 0, not 1.
<?php
$sCSVFile = 'Book1.csv'; // Name of file.
$fp = fopen($sCSVFile,'rt'); // Open file.
while(($aCSV = fgetcsv($fp,10000)) !== False) // Whilst we can get something from the file.
{ // 10000 is the number of lines PHP is to read
if (aCSV[0] == $text_input) {
$pCode = $aCSV; // Store the last thing just read into an array.
}
}
print_r($pCode); // Print the array.
?>
I would highly recommend you use a database, in fact you can purchase Zip/Postal Code databases complete if you would like.
This way you could query the database (MySQL perhaps?) for the Zip/Postal Code and have the city returned.
This function will be extremely slow and is very inefficient.