Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.