我使用此代码读取文件,我在 in_array() 上收到错误警告,因为第二个参数的数据类型错误。
if (isset($_POST['submit'])) {
$SongToAdd = stripslashes($_POST['SongName']) . "\n";
$ExistingSongs = array();
if (file_exists("SongOrganizer/songs.txt") && filesize("SongOrganizer/songs.txt") > 0) {
$ExistingSongs = file("SongOrganizer/songs.txt");
}
}
if (in_array($SongToAdd, $ExistingSongs)) {
echo "<p>The song you entered already exists!<br />\n";
echo "Your song was not added to the list.</p>";
文本文件包含:
Bang Bang
Doctor
Hello
Ice Cream Man
Show Me
Doctor