php array of UK towns/cities
I need a list of towns/cities to be selected in a dropdown menu. I have found this website:
Link
But I require it in a php array, so that I can just loop throu开发者_如何转开发gh it to populate the dropdown. I have searched but cannot find one written in an array, and this one only exports for google earth.
Anyone got a script which does this?
Thanks
Have you considered pulling the data from a database instead to populate the drop down.
http://www.sqldumpster.com/databases/geographic/
Building on this you could push this data into a file and read it like another comment has mentioned... or even manipulate this data into a php style array so you can use it as you intented.
I don't know any scripts offhand, but it wouldn't be too difficult to write one that just screen scrapes the data.
It's very unlikely you will find this in ready-made PHP array form.
Consider simply copy+pasting such a list from your brower into a text file, and opening it in PHP using file()
.
If you download the file, it will save as .php, rename it to file.xml
<?php
if (file_exists('file.xml')) {
$xml = simplexml_load_file('file.xml');
foreach ($xml->Document->Placemark as $item){
$array[] = $item->name;
}
} else {
exit('Failed to open file.xml.');
}
print_r($array);
?>
That will create an array with the handle $array and assign all the Placemark names to the array values. You can easily loop or edit as needed. I have tested this code and it works.
精彩评论