[英]Deleting a record from the table from a file
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我的文件凭证.txt
ub65rf
98huf4
YbyR42
My code PHP我的代码 PHP
$array = [];
$array = file('voucher.txt');
$find = '98huf4';
if (in_array($find, $array))
{
echo "Match found";
}
else
{
echo "Match not found";
}
By default file()
includes the newlines in the strings, so they don't match your $find
string.默认情况下,
file()
包含字符串中的换行符,因此它们与您的$find
字符串不匹配。 There's a flag to remove them.有一个标志可以删除它们。
$array = file('voucher.txt', FILE_IGNORE_NEW_LINES);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.