Alright, so lets say you have a file name "search.txt" and the contents of that file is:
1223
1245
3389
4489
...
and when you're at index.php and you search for "1223", it will return TRUE, but if you search for "12" (which would come back true for 2 occasions because of the first and second line contain "12"), it would come back FALSE because it's not EXACTLY matching the full line.
This is what I have so far, but it's not working:
$uid = $_POST['uid'];
$searchfile = file_get_contents('search.txt');
if (preg_quote($searchfile, $uid) === false)
{
echo "NO";
}
else
{
echo "YES";
}
Thank you for any response!
Not quite sure whether the numbers are separated by line or by space, but if it's by newline then the following one liner should work:
if(array_search($uid, file('search.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) === false) {
echo 'no';
} else {
echo 'yes';
}
If the file doesn't get too big, you could loop through each line with the file()
function:
$lines = file('search.txt');
$uid = $_POST['uid'];
$found = false;
foreach ($lines as $line){
if ($line == $uid)
$found = true;
}
if ($found)
echo 'YES';
else
echo 'NO';