如何从.txt获取这个城市并使用PHP将其添加到数据库? [关闭]

city.txt

City
City1
City2
City3
City4
City One
City Other

How to get this city from .txt and add this to database using PHP?

Its pretty easy. You need to google to read file in PHP and write to database in PHP.

Here I'll start you off:

$file_handle = fopen("cit.txt", "rb");

while (!feof($file_handle) ) {
  $line_of_text = fgets($file_handle);
  // write your insert statement here, depending on your table structure.
}

Or try:

$file = file_get_contents("city.txt");
$cities = explode("
", $file);

foreach ($cities as $city) {

    $SQL = "INSERT INTO table_name (city) VALUES ('$city')";
    //now execute the SQL statement

}