I have a form that the user fills out and they need to enter their zip code. I would therefore like to retrieve the location name of the zip code from a large TXT file containing tab-separated data with zip codes and location names. The zip code is on column 1, while location name is on column 2.
2058 SESSVOLLMOEN 0235 ULLENSAKER G
2060 GARDERMOEN 0235 ULLENSAKER G
2061 GARDERMOEN 0235 ULLENSAKER P
2062 JESSHEIM 0235 ULLENSAKER P
2063 JESSHEIM 0235 ULLENSAKER G
2066 JESSHEIM 0235 ULLENSAKER G
2067 JESSHEIM 0235 ULLENSAKER G
2068 JESSHEIM 0235 ULLENSAKER G
2069 JESSHEIM 0235 ULLENSAKER G
My $input
contains '2069
'. How can I get the city/location name of $input
?
It would've have helped if you provided some examples of what you've already tried and where you're stuck. I'm assuming you're fairly new to php and probably don't know where to look. Here is a piece of code that should work for you:
function searchForValue($val, $table_array) {
foreach ($table_array as $row_string) {
$row_array = explode ("\t", $row_string); //this is a single row converted into a one dimensional array
if ($row_array[0] == $val) {
return ($row_array[1]) ; //second column in the row that contains the city name
break;
}
}
return null;
}
//Read the file contents, assuming file is in the same directory
$text = file_get_contents('SampleText.txt', true);
//Convert the string with all file contents to an array of strings, where each element is a string value corresponding to a row in the file
$zip_table_array = explode("\r\n", $text);
$zip_to_search = '2069';
$city = searchForValue($zip_to_search, $zip_table_array);
echo ("<br>City for zip $zip_to_search is: " . $city ) ;
Hope this helps.
error: selenium.common.exceptions.TimeoutException: Message:
jetpack compose not responding to keyboard input on emulator
Hexagon Grid CSS - All hexagons change size when each of them is clicked
How to render HTML pages as PNG/JPEG images with URL array using Javascript only?
Get count of items that matches a condition from mongo db in node js
“Duplicate entry” even though the column has UNIQUE constraint
I am working on a website that has many directories and subdirectoriesDeveloping locally, I am running php's built in webserver
Using PHP I would like to parse a string of text and replace any emoticons with Unicode emoji charactersFor example, ":)" would be replaced with "
I have TABLE(s) with a datetime field called "Lastcall"I need to delete any records in these tables which are more than (3) days old
When I look in htop, it shows me the following overviewPlease note that they are all sleeping (mode S)?