0

Why are this code not working if i comment out the if statement it prints the file.

<?php

$f = fopen("test.txt", "r");

// Read line by line until end of file
while(!feof($f)) { 
    $arrays = explode("\n",fgets($f));
    foreach($arrays as $words){
        if($words == "andersmarkc"){
            echo $words;
        }
    }
}

fclose($f);

?>
amc
  • 63
  • 1
  • 5
  • what it's not working, what it's the output. Also `\n` it's a break line – Emilio Gort May 01 '17 at 15:15
  • Function fgets() gets a line from file, then if you want words you have to explode this line by the spaces which presumably are between the words, so the line shoud be: $arrays = explode(" ",fgets($f)); – Picard May 01 '17 at 19:09
  • @Picard Thanks worked like a charm – amc May 01 '17 at 21:35

0 Answers0