I'm trying to validate that a php variable value exists in a text file then echo that value. Using the code below, my if statement is only true if the value in the variable is equal to the last value in the text file. If the value in the variable is equal to the first, second, third, etc values the if statement is false.
Here is my code:
$lines = file("file.txt");
$value = $_GET['value'];
foreach ($lines as $line) {
if (strpos($line, $value) !== false) {
$output = $line;
} else {
$output = "Sorry, we don't recognize the value that you entered";
}
}
$outputvariable every time. What do you expect?$output = $line; break;