Jump to content

importing a pipe csv files into a db issue


ollyno1uk

Recommended Posts

Hi

 

I wrote a script a while back that imports a pipe csv files into my database. It worked great until the people who make the file started using some pipes within the string.

 

The strings are separated with quotations but I do not know how to modify this script to not explode the pipes that are contained within;

 

Perhaps someone can point me in the right direction.


$url = 'url of feed';
$content = file_get_contents($url);

$array = explode("\n", $content);

foreach($array as $line_number=>$line){


$column = explode('|', $line);



$query = "insert into table set
column1 = $column[0],
column2 = $column[1],
column3 = $column[2]; 

I presume so - you can use file_get_contents to grab the content, create a file on the server something like:

$filename='tmp'.time().'.csv';

Then read the file in using fgetcsv() once you open() the file you created for reading.

 

Once finished, unless you need to keep the contents of the file you can use unlink() to delete it.

 

unlink($filename);

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.