我對PHP非常陌生,無法找到如何解決這個問題。我有一個表單,並希望將一些字符串傳遞給它,並使用另一個文件進行檢查。如果所有字符串都在同一行上,但是一旦我放入多行字符串,就會失敗。我無法獲得strpos與新行一起工作
我有下面的代碼的PHP文件:
<?php
echo "<center><form method='post' enctype='multipart/form-data'>";
echo "<b></b><textarea name='texttofind' cols='80' rows='10'></textarea><br>";
echo "<input name='submit' type='submit' style='width:80px' value='Run' />";
echo "</form></center>";
$texttofind = $_POST['texttofind'];
if(get_magic_quotes_gpc()) {
$texttofind = stripslashes($texttofind);
}
$texttofind = html_entity_decode($texttofind);
$s = file_get_contents ("/home/xxxxx/public_html/abc.txt");
if (strpos ($s, $texttofind) === false) {
echo "not found";
}
else
echo "found";
?>
和的abc.txt,我有
dog
cat
rat
每當我打開PHP頁面,並輸入在短短的狗或貓,它會沒事,並顯示'found'
消息,但是當我輸入多行像'狗<enter on keyboard>
貓',然後單擊提交按鈕,它將返回'not found'
消息。
代碼有什麼問題,或者無論如何要適應它,以便它能夠搜索多行?
預先感謝您。
所以,如果你在兩行提交兩個詞,那麼你要同時檢查?一個簡單的循環會在這裏執行 –
你的文件可能使用(說)'\ n'作爲行分隔符,但是你的瀏覽器正在發送'\ r \ n'。 –
從Hanky獲得了工作代碼。問題已經解決了。感謝Hanky,Dan和Marc。 – user1951663