我遇到了一些代码问题。它是一个HTML文件,它将字符串发送到PHP文件,然后搜索脱机数据库并返回指向html页面的链接。每次我搜索它时都没有找到结果。
<?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>
提前感谢您提供的任何帮助。
答案 0 :(得分:2)
第一个问题是,您正在查看$ _GET [&#39;关键字&#39;]变量,但您的输入名称是搜索。
变化:
$searchfor=$_GET['keyword'];
要:
$searchfor=$_GET['search'];
如果你能告诉我们你的html文件的格式会很棒。
并将文件路径更改为: https://ebooks.adelaide.edu.au/s/shakespeare/william/
<强>更新强>
最后,这样的事情应该有效(但它仍然很难看)
$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>";
}