X
X
xuxubla2015-05-15 09:39:47
PHP
xuxubla, 2015-05-15 09:39:47

Is it possible to change a specific row in a CSV file?

There is a database of store products in a CSV file. You need to check each row for updates. Passed the line -> there is a change -> overwrote the line without touching the rest.
How data is stored in CSV (with example):

item_id; item_ean; item_name; item_price
1; 121hggh;Table; 2300

The product parser from a third-party store writes data for each product into an array (example):
array {
$item_id = 1,
$item_ean = '121hggh',
$item_name = 'Table', $ item_price
= 2,350.00}
the price has changed.
How can I have only one row (ideally one value) in a CSV file without overfilling the rest?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zakharov Alexander, 2015-05-15
@AlexZaharow

Not enough data to think about. Even if the option is standard Base and CSV import, then not everything is clear.
If there is a key field, then there is no problem. If not, then everything is somewhat more complicated, sometimes even impossible. Can you give me a little more information about the database and CSV?

V
Valery Ryaboshapko, 2015-05-15
@valerium

And what prevents you from acting like a white man, that is, parsing CSV, looping through it and correcting the necessary values, and then writing this data back to a file?
In the end, if the file is huge (hundreds of megabytes), you can read, edit and write it line by line. Although, to optimize the work with the disk, it is better not to have one line, but ten (depending on how long the line is).
Yes, the script will work on a huge file for a long time, maybe even a few minutes. But files are what they are. Need speed - take the database.
It is theoretically possible to correct only one value, but you will not get hemorrhoids. For example, imagine a situation where you need to not just change a couple of bytes, but add them to the middle of a file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question