Created
December 30, 2022 14:33
-
-
Save thedarsideofit/0038c3062c0502808d488e0955d0cbb8 to your computer and use it in GitHub Desktop.
Script to parse a list of jurisdictions - (created by chatGPT with some personal enhancements)
This file contains hidden or 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 | |
// Your code here! | |
$text = "Alameda01 Alameda CACCS | |
Alpine02 Alpine CACCS | |
Amador03 Amador CACCS | |
Butte04 Butte CACCS | |
Calavera05 Calaveras CACCS | |
CCosta07 Contra Costa CACCS | |
Colusa06 Colusa CACCS | |
DNorte08 Del Norte CACCS | |
ElDorado09 El Dorado CACCS | |
Fresno10 Fresno CACCS | |
Glenn11 Glenn CACCS | |
Humboldt12 Humboldt CACCS | |
Imperial13 Imperial CACCS | |
Inyo14 Inyo CACCS | |
Kern15 Kern CACCS | |
Kings16 Kings CACCS"; | |
// Split the text into lines | |
$lines = explode("\n", $text); | |
// Initialize an empty associative array | |
$result = array(); | |
// Loop through each line | |
foreach ($lines as $line) { | |
// Split the line into parts | |
$parts = explode(" ", $line); | |
// The first part is the key, and the rest is the value | |
$key = array_shift($parts); | |
// Remove the last three elements (CACCS) from the value | |
array_pop($parts); | |
$value = implode(" ", $parts); | |
// Add the key and value to the array | |
$result[$key] = $value; | |
} | |
// Now $result is an associative array with the keys and values from the text, without the "CACCS" string | |
print_r($result); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment