webent Posted June 8, 2008 Share Posted June 8, 2008 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? Quote Link to comment Share on other sites More sharing options...
rarebit Posted June 8, 2008 Share Posted June 8, 2008 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...) Quote Link to comment Share on other sites More sharing options...
webent Posted June 8, 2008 Author Share Posted June 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
rarebit Posted June 8, 2008 Share Posted June 8, 2008 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... Quote Link to comment Share on other sites More sharing options...
webent Posted June 8, 2008 Author Share Posted June 8, 2008 K... thanks rarebit Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.