0

I downloaded the data from the file and saved it to the table, then I try to search the array and write "Match found" if it is in the table, if I do not write "Match not found"

my file voucher.txt

ub65rf
98huf4
YbyR42

My code PHP

$array = [];
$array = file('voucher.txt');

$find = '98huf4';


if (in_array($find, $array))
  {
  echo "Match found";
  }
else
  {
  echo "Match not found";
  }

1 Answers1

2

By default file() includes the newlines in the strings, so they don't match your $find string. There's a flag to remove them.

$array = file('voucher.txt', FILE_IGNORE_NEW_LINES);
Barmar
  • 741,623
  • 53
  • 500
  • 612