0

I have a problem with PHP. I need to find out, if first row of .CSV file contains exact value. So far I tried:

$file = file_get_contents("./file.csv");
    if (strpos($file, "Value") !== false) {
        echo "Found";
    }

How to check, if first line of .CSV file contains text that says "Value"?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
JustinasT
  • 561
  • 1
  • 8
  • 27
  • 2
    Look at http://php.net/manual/en/function.file.php and then use index `0` or `1` (depending on if you have headings). – chris85 Dec 07 '15 at 22:37
  • 3
    If the CSV is huge reading it all in with file_get_contents just to compare the first line isn't really efficient. [Check out](http://stackoverflow.com/questions/4521936/quickest-way-to-read-first-line-from-file) some of these answers to see which method might be the best for you. – Dave Chen Dec 07 '15 at 22:54

1 Answers1

0

Issue solved by looking exact places where I need to look :)

if (strpos($data[0],'Value') !== false)
JustinasT
  • 561
  • 1
  • 8
  • 27