Php in_数组函数(从文件中读取,而不是在行中读取)
我试图从.txt文件中读取单词(每行一个单词), 目前,我拥有PHP代码中的所有单词,但我希望从txt文件中读取:Php in_数组函数(从文件中读取,而不是在行中读取),php,Php,我试图从.txt文件中读取单词(每行一个单词), 目前,我拥有PHP代码中的所有单词,但我希望从txt文件中读取: <?php $user = $_GET['user']; if (in_array($_GET['user'], ['User1', 'User2'])) { }else { echo "You are not in the list"; die; } ?> 如何更改第二行代码:() 提前谢谢 试试这段代码,告诉
<?php $user = $_GET['user'];
if (in_array($_GET['user'], ['User1', 'User2']))
{
}else
{
echo "You are not in the list";
die;
}
?>
如何更改第二行代码:()
提前谢谢 试试这段代码,告诉它显示了什么var_dump($users) test.php
<?php
$user = $_GET['user'];
$users = file('users.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
var_dump($users);
if (in_array($user, $users)) {
echo $user;
} else {
echo "You are not in the list";
die;
}
尝试此代码并告诉它显示了什么var_dump($users) test.php
<?php
$user = $_GET['user'];
$users = file('users.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
var_dump($users);
if (in_array($user, $users)) {
echo $user;
} else {
echo "You are not in the list";
die;
}
Php文件函数读取
和逐行和返回数组
function exists($user)
{
return (bool) in_array($user,file('users.txt'));
}
echo exists($_GET['user']); // true or false
例如users.txt
admin
Foo
moderator
John
查看php读取文件函数
Php文件函数读取
和逐行和返回数组
function exists($user)
{
return (bool) in_array($user,file('users.txt'));
}
echo exists($_GET['user']); // true or false
例如users.txt
admin
Foo
moderator
John
查看php读取文件函数
使用$data=file('path_to_file',file_IGNORE_NEW_line | file_SKIP_EMPTY_line)$playerlist=file('spieler.txt',file_IGNORE_NEW_line | file_SKIP_EMPTY_line);如果(在_数组($_GET['user',$playlist])中)似乎不起作用:/the$_GET['user'];需要检查.txt文件,因此test.php?user=User1和test.php?user=User2可以,而test.php?user=User3将导致“您不在列表中”使用$data=file('path_to_file',file_IGNORE_NEW_line | file_SKIP_EMPTY_line)$playerlist=file('spieler.txt',file_IGNORE_NEW_line | file_SKIP_EMPTY_line);如果(在_数组($_GET['user',$playlist])中)似乎不起作用:/the$_GET['user'];需要检查.txt文件,因此test.php?user=User1和test.php?user=User2就可以了,而test.php?user=User3将导致“您不在列表中”数组(2){[0]=>string(4)“Niko”[1]=>string(7)“Patrick”}Nikocode work test.php?user=Niko return Niko和test.php?user=aaaa return您不在列表中(2){[0]=>string(4) “Niko”[1]=>string(7)“Patrick”}Nikocode work test.php?user=Niko return Niko and test.php?user=aaaa return您不在列表中