Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to create an array of values ($import_data) from a csv file that contains about 42,000 rows, each row contains an SKU. I only want to add the values to the array which DO NOT contain the string "CNV". Is there an easy way to do this?

Here is how I am adding the values from the CSV to the array:

while ( ( $line = fgetcsv($handle, 0, $post_data['import_csv_separator']) ) !== FALSE ) {
            $import_data[] = $line;
        }
share|improve this question
    
have you tried using strpos() function ? –  Maximus2012 Aug 9 '13 at 20:22
1  
something like this maybe: if (strpos($line, "CNV") === false){ // do something} –  Maximus2012 Aug 9 '13 at 20:26
    
This helped me so much! Thank you! I'll answer my question with my final code. Thanks again! –  rubyme8 Aug 9 '13 at 20:42

1 Answer 1

up vote 0 down vote accepted

This solved it!

         while ( ( $line = fgetcsv($handle, 0, $post_data['import_csv_separator']) ) !== FALSE ) {
            $test_str = print_r($line,true);
            if (strpos($test_str, "CNV") === false){ // add it
            $import_data[] = $line;
         } 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.