Jump to content

finding duplicate fields in file


webent

Recommended Posts

Hi guys, me again... Come to find out, my product files provided by various suppliers contain duplicate model numbers for completely different products, Go Figure... LOL

 

So I'm having to do some pre-database-loading, file integrity checking... Here's what I got so far...

 

<?
function preCheckFile($_POST) {
$handle = fopen($_POST['file_name'], "r");
while (($fields = fgetcsv($handle, 0, ",")) !== FALSE) {
// Begin check for duplicate model numbers in the csv file
$products_model = $fields[$_POST['products_model']];

// End check for duplicate model numbers in the csv file    
}
}  
?>

 

So I guess what I'm asking, is there an easy way that I'm just not getting to check if the $products_model is duplicated within the file without having to upload all of them into a temporary table and then re-query them?

Link to comment
Share on other sites

Long, but you could put the whole csv into an array and then loop through it recursively checking it for the current element...

 

alternatively...

 

Run some kind or regex (grep/awk/php based?) checking script on the files... (similar to above but a lot faster and less memory intensive...)

Link to comment
Share on other sites

Long, but you could put the whole csv into an array and then loop through it recursively checking it for the current element...

 

alternatively...

 

Run some kind or regex (grep/awk/php based?) checking script on the files... (similar to above but a lot faster and less memory intensive...)

 

Know of any examples of regex (grep/awk/php) I've never heard of it before... not exactly sure what to google for... LOL... regex or grep or awk :)

Link to comment
Share on other sites

It's origionally a perl thing (I think) and is known as 'regular expressions' (or regex for short). Here's the local forum http://www.phpfreaks.com/forums/index.php/board,43.0.html, there's some help topics at the top.

 

GREP and AWK are programs that generally come with linux, I suggested AWK because it is especially adapted to work well with csv's. I believe that both of these are available on winnie, even if with cygwin or mingw (you get a mini version of bash with one of them). Well, err getting a bit beyond, i'd just reask your question in the regex forum above...

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.