私はPHPのいくつかの弱点を学び始めたばかりです..私は検索ボックスに取り組んでいますが、結果を得ることができません
<html>
<head><title>Search Form</title></head>
<body>
<form action="12.html" method="GET">
<input type="text" name="keyword" id="keyword width="50" value="" />
<input type="submit" value="Search"/>
</form>
</body>
</html>
<?php
$searchfor = $_GET['keyword'];
$file = '12.html';
$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*$pattern.*\$/m";
if(preg_match_all($pattern, $contents, $matches)){
echo "Found matches:<br />";
echo implode("<br />", $matches[0]);
}
else{
echo "No matches found";
fclose ($file);
}
?>
私の検索用コンテンツは 12.html ファイルにあります。検索ボックスに単語を入力すると、ページの本文全体が結果として表示され、特定の行または単語が必要です。コンテンツにない単語を入力しても。私のファイルの本体は、私がどこで間違いを犯したのかわからないことを示しています。