Jump to content

why can't update the record in the csv file?


runeveryday

Recommended Posts

There are 50 csv files. each csv file have the same column's name. some content in the column are the same, some don't.

 

eg:test1.csv,  example1.csv, hello.csv,  world.csv.......test70.csv.

now, i want to make a change to two column's content.

 

a, all csv files have a column named qty. whose rows content are all 0. now, i want to change it into

 888

 

b, all csv files have a column named image. whose rows content are all

 

 upload/img1.jpg
upload/img2.jpg
upload/img3.jpg
upload/img01.jpg
upload/img14.jpg
upload/img01.jpg
.......

If i open each csv file then do a search and replace. i fell it too bored.

 

Thank you in advance.

 

 

i want to delete Uploadin the image column, change 0 to 888 in the qty column.

 

i using the file change.php to update the record.

 

one csv file. http://phplist.xxmn.com/women.csv

 

 

 

the code:

 

<?php
$dir    = getcwd();
$files = array_diff(scandir($dir), array('..', '.','change.php'));
foreach ($files as $file) {
    if (($handle = fopen($file, "r")) !== FALSE) {
        $new_content = '';
        while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
            //var_dump($data);
           $data[2]=888; 
            $new_content .= implode(',', $data);
            //var_dump($new_content);
        }
       file_put_contents($file, $new_content);
        echo 'down';
    }
}

?>

 

the code doesn't work how to correct it . thank u

Link to comment
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.