Jump to content

[SOLVED] Reading a TXT


Perfidus

Recommended Posts

Hi there, I have a huge TXT with a list of streets:

 

street 1

street 2

street 3

 

I would like the php to read them and place them in the same order as they appear in the database inside the street column.

I know how to do it when txt looks like

 

street 1, street 2, street 3

 

but don't know how to handle with the line breaks.

Any hints?

Link to comment
https://forums.phpfreaks.com/topic/78244-solved-reading-a-txt/
Share on other sites

Uppps, I forgot to include the execution inside the bucle !!!

By the way, can I read two TXT simultaneously to add the ZIP's to the database, cause I have another list with all the zip codes in the same order as streets are...

 

I guess this is SCIFI, isn't it?

 

<?php

 

  $lines = file('streetsfile.txt');

  $lines2 = file('zipsfile.txt');

 

  foreach (($lines as $line)&&($lines2 as $line2)) {

    $sql = "INSERT INTO tbl (street, zip) VALUES ('$line', '$line2');

    // execute query.

  }

 

?>

Link to comment
https://forums.phpfreaks.com/topic/78244-solved-reading-a-txt/#findComment-396052
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.