【发布时间】:2014-04-24 22:28:25
【问题描述】:
我已经设置了文件,因此它具有这样的用户名
姓名1
名字2
名字3
$tuser = implode(" ", $this->arguments);
$line = file("tready.txt", FILE_IGNORE_NEW_LINES);
$line_check = implode(" ", $line);
$search_string = $tuser;
if (!empty($tuser)) {
if (stripos($line_check, $search_string) !== FALSE) {
$this->say('Your already on the list!');
} else {
file_put_contents("tready.txt", $tuser, FILE_APPEND);
$this->say('Your team has been added to the list: ' . $tuser);
}
} else {
$this->say('Invalid Entry. !Addme [username]');
}
它没有做的是:
if (stripos($line_check, $search_string) !== FALSE)
在脚本运行之前,我已经检查了 $line_check 和 $search_string 的回显,它们显示正确,但是当它们检查自己时,某些东西不能正常工作,它允许脚本无论如何添加它们。我是否使用了错误的程序?
【问题讨论】:
-
当您可以使用 file() 并与 array_search() 匹配时,为什么要进行所有字符串恶作剧