I respectfully ask you guys to sort through this and let me know the result. I'm happy to implement anything that makes the site more useful.
Well, I'm assuming here that the issue is that the catalog on your back end does not know the ICAO (K-ified) identifiers. In which case, Ed's solution will work great for the contiguous US, to translate the "K's" into "non-K's" so they can be looked up in the catalog.
However, if your catalog does not have the ICAO's, there's no way to automatically translate Alaskan/Hawaiian "P" identifiers into "non-P" identifiers and the "chopping letters" trick won't work there. The only way to recognize both is to have something on the back end that actually has the ICAO identifiers in its database; see
https://airportcodes.aero/icao/P for a list of them. So maybe your code could query some kind of internet database... but probably the easiest/laziest way -- what I would do -- is to just cut-and-paste this whole "P" list and incorporate it into a big ol' Ed-style if statement:
icaohash = { # define a list of weird ICAO's, each associated with the corresponding non-ICAO
PAAK: AKB,
PAAQ: PAQ,
PABA: BTI,
<etc etc etc... put the whole list here>
}
if (identifier in icaohash): # if it's one of these edge cases....
identifier = icaohash[identifier] # overwrite it with the non-ICAO one
<and then Ed's if-statement to overwrite any 4-character K thing with the non-K thing>
Another weird edge-case: Tok Junction, Alaska is "PFTO" or "6K8". But it doesn't show up on these lists of ICAO identifiers for some reason, though that's how it's listed on the charts and in GPS's and whatnot. I don't know what the deal is with that one. But Tok Junction does have a restaurant across the street from the airport... I've entered four restaurants for ya today! OK, time to put the computer down...!