Php 从文件中删除表中的记录
我从文件中下载了数据并将其保存到表中,然后尝试搜索数组,如果它在表中,则写入“Match found”,如果不写入“Match not found” 我的文件凭证.txtPhp 从文件中删除表中的记录,php,arrays,Php,Arrays,我从文件中下载了数据并将其保存到表中,然后尝试搜索数组,如果它在表中,则写入“Match found”,如果不写入“Match not found” 我的文件凭证.txt ub65rf 98huf4 YbyR42 我的PHP代码 $array = []; $array = file('voucher.txt'); $find = '98huf4'; if (in_array($find, $array)) { echo "Match found"; } else {
ub65rf
98huf4
YbyR42
我的PHP代码
$array = [];
$array = file('voucher.txt');
$find = '98huf4';
if (in_array($find, $array))
{
echo "Match found";
}
else
{
echo "Match not found";
}
默认情况下,file()
在字符串中包含换行符,因此它们与$find
字符串不匹配。有一面旗子可以移除它们
$array = file('voucher.txt', FILE_IGNORE_NEW_LINES);
默认情况下,file()
在字符串中包含换行符,因此它们与$find
字符串不匹配。有一面旗子可以移除它们
$array = file('voucher.txt', FILE_IGNORE_NEW_LINES);