Hey, I'm trying to make a form of a search engine for my website. I have permission from my teacher to do it for class even though its for personal use. I have part of it built but I'm stuck at the "proper translation of the file" part. Heres the primary file's code:
<html>
<head>
<title>Search Engine Test</title>
</head>
<body>
<form name="search" method="POST" action="search.php">
<input type="text" name="search_string" value="">
<input type="submit" name="submit" value="search"
</form>
</body>
</html>
This is the part that I don't have any problems with. Thent heres the function of my script that I'm having the problem with:
<html>
<body>
<?php
$search_text = file("search_text.txt");
$search_string = $_POST['search_string'];
foreach($search_text as $key => $val)
{
$data[$key] = explode("||", $val);
}
echo 'Search Results for "'.$search_string.'"';
echo "<br><br>";
for($k = 0; $k < sizeof($search_text); $k++)
{
if ($search_string == $data[$k][0] or $data[$k][1] or $data[$k][2] or $data[$k][3])
{
echo '<a href="'.$data[$k][5].'">'.$data[$k][4].'</a>';
echo '<br><br>';
}
else
{
echo "<br><br><br>";
echo "Your search returned 0 results. Please go back and try again.";
}
}
?>
</body>
</html>
What I'm trying to do is make it read this file for the search info:
toy||red||truck||large||Big Red Truck||bigredtruck.html
pie||apple||truck||small||Apple Pie Truck||applepietruck.html
dog||brown||small||annoying||Annoying Brown Dog||browndog.html
cat||tan||large||annoying||Annoying Tan Cat||tancat.html
(The links don't really matter they are just references for the script, I'm going to change them later.)
When it reads the file its suppose to explode the || and label each part as a tag (parts 0-3 are tags, part 4 is the title, and part 5 is the link to go to. My problem is that when it reads the file if it finds even one matching tag it shows everything. This is where I'm stuck. I want it to only show the title/link combo that has the matching tag. Can someone help me or at least tell me if this is possible?