Reputation:
I have an issue with some code. It's a HTML file that sends a string to a PHP file which then searches an offline database and it returns a link to the html page. Each time I search it states there are no results found.
<?php $searchfor=$_GET['keyword'];
$contents=file_get_contents('/users/tutors/mhtest15/share/shakespeare/home.html', true);
if (stripos($contents, $searchfor) !==false) {
$startpos=stripos($contents, $searchfor);
$getcode=substr($contents, $startpos, 150);
$isolate=explode('"', $getcode);
$sendlinkback='https://ebooks.adelaide.edu.au/s/shakespeare/william/'.$isolate[1];
echo "<br> <a href ='".$sendlinkback ."'>The file $searchfor Exists here</a>";
}
else if ($isolate !=='$searchfor') {
echo "<li>no results to display</li>";
}
?>
<html>
<head>
<title>William Shakespeare Archive Search Engine</title>
</head>
<body>
<p>
<p>
<div id="container">
<center><img src="https://s-media-cache-ak0.pinimg.com/originals/fc/20/b4/fc20b40a4447af0bc71746bf47d2849e.jpg" alt="Shakespeare Image" height="400" width="350">
<h1>Shakespeare Search Engine</h1>
</center>
<div style="text-align: center">
<br>
<form action='test.php' method="GET" id="search" name="search">
<input class="button" type="submit" value="Search">
<input name='search' style="width:200px;font-size:14pt;" placeholder="Search term...">
</form>
</div>
</div>
</body>
</html>
Thanks in advance for any help provided.
Upvotes: 1
Views: 73
Reputation: 741
The first issue is, you are checking the $_GET['keyword'] variable, but your input name is search.
Change:
$searchfor=$_GET['keyword'];
To:
$searchfor=$_GET['search'];
If you can show us the format of your html file would be great.
And change file path to this: https://ebooks.adelaide.edu.au/s/shakespeare/william/
UPDATE:
Finally, something like this should work (but it's still ugly)
$searchfor=$_GET['search'];
$contents=file_get_contents('https://ebooks.adelaide.edu.au/s/shakespeare/william/', true);
if (stripos($contents, $searchfor) !==false) {
$startpos=stripos($contents, $searchfor);
$getcode=substr($contents, $startpos, 150);
$isolate=explode('"', $getcode);
$sendlinkback='https://ebooks.adelaide.edu.au/s/shakespeare/william/'.$isolate[0];
echo "<br> <a href ='".$sendlinkback ."'>The file ".preg_replace('/^>/','',strip_tags($isolate[1]))." Exists here</a>";
}
Upvotes: 2