解析错误:语法错误,第 116 行 C:\Program Files\XAMPP\htdocs\lookup.php 中的文件意外结束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18710522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse error: syntax error, unexpected end of file in C:\Program Files\XAMPP\htdocs\lookup.php on line 116
提问by Gtfo_My_Nuts
So I have been trying to get this search script to run locally with XAMPP and that's the error I have been getting, any tips? I don't know much about programming hence why I'm asking, I got the script from a public source and was just trying to set it up locally.
所以我一直试图让这个搜索脚本使用 XAMPP 在本地运行,这就是我遇到的错误,有什么提示吗?我对编程不太了解,因此我为什么要问,我从公共来源获得了脚本,只是想在本地进行设置。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Search Engine</title>
<style type="text/css">
.footertext{
position:center;
bottom:0;
}
body {
background-color: #202020;
}
body,td,th {
color: #CCC;
font-family: Verdana, Geneva, sans-serif;
}
.searchbox {
font-family: Verdana, Geneva, sans-serif;
font-size: 18px;
color: #CCC;
background-color: #333;
border: 1px solid #CCC;
padding-left: 10px;
}
</style>
</head>
<body>
<div align="center">
<a href=""><img border="0" src="" alt ="logo"></a>
<br>
<br><a href="/dblookup.php/"><b><u>Search Again</u></b></a>
<br>How to use: <br>Input search term and click search.
</div>
<div align="center">
<?php
$fname = strlen(htmlspecialchars($_POST['text']));
if (isset($_POST['text'])){
$directory = "";
//get all image files with a .jpg extension.
$images = glob($directory . "*.txt");
//print each file name
foreach($images as $image)
{
if($fname<3)
{
echo "You must have atleast 4 characters in your search, Sorry.";
return;
}
$file = $image;
$searchfor = $_POST['text'];
// the following line prevents the browser from parsing this as HTML.
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*$/mi";
//require "sanitize.php";
// search, and store all matching occurences in $matchess
if(preg_match_all($pattern, $contents, $matches)){
echo "<br><br>Found matches in $file:<br />";
//$nigga = array_map("htmlspecialchars", $matches);
//vv this part
$gud = implode("\n", $matches[0]);
//#####################^ htmlspecialchars($matches[0]) -> But it doesnt output anything..
//#This part ^^
echo nl2br(htmlspecialchars($gud));
}else{
echo "";
}
}
} else {
?>
</div>
<form action='' method='post'>
<div align="center">Search: <br><input name='text' type='text' class="searchbox">
<input type='submit' class="searchbox" value='Search'>
</div>
</form>
<? } ?>
<div class="footertext">
<br><br><br>
<center>Lookup: <a href="">Lookup</center>
</div>
</body>
</html>
回答by vee
It appears that your php configuration is not allowing short_open_tags.
看来您的 php 配置不允许short_open_tags。
Replace the following line:
替换以下行:
<? } ?>
with:
和:
<?php } ?>
Here is the working version of your code after the fix in phpfiddle: http://phpfiddle.org/main/code/8sm-b3g
这是在 phpfiddle 中修复后代码的工作版本:http://phpfiddle.org/main/code/8sm-b3g
回答by Jasmin Mistry
Note:PHP short tags are deprecated in newer version.
注意:PHP 短标签在较新版本中已弃用。
change this line
改变这一行
<? } ?>
to
到
<?php } ?>
回答by Pupil
In your PHP's settings, the directive short_open_tags is not enabled.
If this directive is enabled, PHP can run with the tags: <? ?>
.
Therefore, it will show error on <? ?>
and must require <?php ?>
.
If you want your file to run with <? ?>
, go to your php.ini
file.
And uncomment the line:
在您的 PHP 设置中,指令 short_open_tags 未启用。如果启用此指令,PHP 可以使用以下标签运行:<? ?>
. 因此,它将显示错误<? ?>
并且必须 require <?php ?>
。如果您希望您的文件与 一起运行<? ?>
,请转到您的php.ini
文件。并取消注释该行:
short_open_tag = Off
short_open_tag = Off
change it to:
将其更改为:
short_open_tag = On
short_open_tag = On
And you code will work.
你的代码会起作用。