如果我在我的表单中输入 Test1 输出是 5x Test1,如果我在我的表单中输入 Test2 输出是 4x Test2 等等。我该如何解决这个问题?
这是我的 csv 文件:
“纳姆”
“测试1”
“测试2”
“测试3”
“测试4”
这是我的搜索表单:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="test.css">
<title>test</title>
</head>
<body>
<div id="container">
<div id="logo"></div>
<div id="header">
<h1>Test Test Test</h1>
</div>
<div id="menu"></div>
<div id="content">
<form action="csv.php" method="post">
<h3>Voer je naam in:</h3>
<pre>
Naam: <input type="text" name="Naam"><br>
<input type= submit name="submit" value="Verzenden">
</pre>
</form>
</div>
</div>
<div id="footer"></div>
</div>
</body>
</html>
这是输出页面:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="test.css">
<title>test</title>
</head>
<body>
<div id="container">
<div id="logo"></div>
<div id="header">
<h1>Test Test Test</h1>
</div>
<div id="menu"></div>
<div id="content">
<form method="get">
<?php
if ( !empty ( $_POST['Naam']) ) {
$naam = $_POST['Naam'];
$file_handle = fopen("Test.csv", "rb");
$found = false;
while (!feof($file_handle) ) {
$parts = fgetcsv($file_handle,4096,",");
$file_arr = preg_split ( "/\n/" , $file_content );
foreach ( $file_arr as $item ) {
if ( $parts[0] == $naam ) {
$found = true;
$resultaat = $parts[0];
}
}
$parts[0] = ucwords(strtolower($parts[0]));
if ( $found ) {
Print "Naam: ". $resultaat; echo "<br>";
}
}
if ( !$found ) {
print "Not found";
}
fclose($file_handle);
}
?>
</div>
<div id="footer"></div>
</div>
</body>
</html>