<?php
if(!isset($_GET['s'])) {
die('You must define a search term!');
}
$highlight = true;//highlight results or not
$search_in = array('html', 'htm');//allowable filetypes to search in
$search_dir = '..';//starting directory
$recursive = true;//should it search recursively or not
define('SIDE_CHARS', 80);
$file_count = 0;
$search_term = mb_strtolower($_GET['s'], 'UTF-8');
//$search_term = $_GET['s'];
$search_term_length = strlen($search_term);
$final_result = array();
$files = list_files($search_dir);
foreach($files as $file){
$contents = file_get_contents($file);
preg_match("/\<title\>(.*)\<\/title\>/", $contents, $page_title); //getting page title
if (preg_match("#\<body.*\>(.*)\<\/body\>#si", $contents, $body_content)){ //getting content only between <body></body> tags
$clean_content = strip_tags($body_content[0]); //remove html tags
$clean_content = preg_replace( '/\s+/', ' ', $clean_content ); //remove duplicate whitespaces, carriage returns, tabs, etc
//$found = strpos_recursive($clean_content, $search_term);
$found = strpos_recursive(mb_strtolower($clean_content, 'UTF-8'), $search_term);
$final_result[$file_count]['page_title'][] = $page_title[1];
$final_result[$file_count]['file_name'][] = $file;
}
if($found && !empty($found)) {
for ($z = 0; $z < count($found[0]); $z++){
$pos = $found[0][$z][1];
$side_chars = SIDE_CHARS;
if ($pos < SIDE_CHARS){
$side_chars = $pos;
$pos_end = SIDE_CHARS + $search_term_length;
}else{
$pos_end = SIDE_CHARS*2 + $search_term_length;
}
$pos_start = $pos - $side_chars;
$str = substr($clean_content, $pos_start, $pos_end);
$result = preg_replace('#'.$search_term.'#ui', '<span class="search">\0</span>', $str);
//$result = preg_replace('#'.$search_term.'#ui', '<span class="search">'.$search_term.'</span>', $str);
$final_result[$file_count]['search_result'][] = $result;
}
} else {
$final_result[$file_count]['search_result'][] = '';
}
$file_count++;
}
?>
<!DOCTYPE HTML>
<html lang="en-US" class="iframe">
<head>
<title>Search results</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="search.css">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<link href='http://fonts.googleapis.com/css?family=Dosis:400' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Dosis:700' rel='stylesheet' type='text/css'>
<![endif]-->
</head>
<body>
<script>
;(function(){
document.body.onload=resize
window.onresize=resize
function resize(){
parent._resize(document.getElementById('search-results').offsetHeight)
}
})()
</script>
<div id="search-results">
<ol class="search_list">
<?php
$match_count = 0;
for ($i=0; $i < count($final_result); $i++){
if (!empty($final_result[$i]['search_result'][0]) || $final_result[$i]['search_result'][0] !== ''){
$match_count++;
?>
<li>
<h4 class="search_title"><a target="_top" href="<?php echo $final_result[$i]['file_name'][0]; ?>" class="search_link"> <?php echo $final_result[$i]['page_title'][0]; ?> </a></h4>
...<?php echo $final_result[$i]['search_result'][0]; ?>...
<span class="match">Terms matched: <?php echo count($final_result[$i]['search_result']); ?> - URL: <?php echo $final_result[$i]['file_name'][0]; ?></span>
</li>
<?php
}
}
if ($match_count == 0) {
echo '<li style="margin-left: -15px; background: #fff;"><h4>No results found for <span class="search">'.$search_term.'</span></h4></li>';
}
?>
</ol>
</div>
</body>
</html>
<?php
//lists all the files in the directory given (and sub-directories if it is enabled)
function list_files($dir){
global $recursive, $search_in;
$result = array();
if(is_dir($dir)){
if($dh = opendir($dir)){
while (($file = readdir($dh)) !== false) {
if(!($file == '.' || $file == '..')){
$file = $dir.'/'.$file;
if(is_dir($file) && $recursive == true && $file != './.' && $file != './..'){
$result = array_merge($result, list_files($file));
}
else if(!is_dir($file)){
if(in_array(get_file_extension($file), $search_in)){
$result[] = $file;
}
}
}
}
}
}
return $result;
}
//returns the extention of a file
function get_file_extension($filename){
$result = '';
$parts = explode('.', $filename);
if(is_array($parts) && count($parts) > 1){
$result = end($parts);
}
return $result;
}
function strpos_recursive($haystack, $needle, $offset = 0, &$results = array()) {
$offset = stripos($haystack, $needle, $offset);
if($offset === false) {
return $results;
} else {
$pattern = '/'.$needle.'/ui';
preg_match_all($pattern, $haystack, $results, PREG_OFFSET_CAPTURE);
return $results;
}
}
?>
没有合适的资源?快使用搜索试试~ 我知道了~
万圣节主题HTML网站模板是一款鬼节节日主题的HTML网站模板。_html网站模板_网页源码移动端前端_H5模板_自适.rar
共59个文件
jpg:14个
js:12个
png:11个
3 下载量 4 浏览量
2023-08-05
16:16:18
上传
评论
收藏 697KB RAR 举报
温馨提示
万圣节主题HTML网站模板是一款鬼节节日主题的HTML网站模板。_html网站模板_网页源码移动端前端_H5模板_自适.rar
资源推荐
资源详情
资源评论
收起资源包目录
万圣节主题HTML网站模板是一款鬼节节日主题的HTML网站模板。_html网站模板_网页源码移动端前端_H5模板_自适.rar (59个子文件)
万圣节主题HTML网站模板是一款鬼节节日主题的HTML网站模板。
chahua3066
index-1.html 6KB
js
jquery.carouFredSel-6.1.0-packed.js 36KB
PIE.php 613B
forms.js 6KB
PIE.htc 40KB
jquery.touchSwipe.min.js 4KB
html5shiv.js 2KB
superfish.js 4KB
jquery.easing.1.3.js 8KB
jquery.equalheights.js 1KB
jquery.js 90KB
jquery-migrate-1.1.1.js 7KB
jquery.countdown.js 4KB
script.js 758B
bat
MailHandler-sub.php 1KB
MailHandler.php 1KB
index-3.html 7KB
css
style.css 8KB
superfish.css 1KB
reset.css 771B
jquery.countdown.css 2KB
form.css 2KB
grid.css 5KB
ie.css 224B
index-4.html 6KB
search
search.js 531B
results.php 5KB
search.css 1KB
search.php 3KB
index-2.html 6KB
index.html 8KB
index-5.html 6KB
images
page5_img6.jpg 33KB
page3_img3.jpg 41KB
page1_img1.jpg 19KB
creep3.png 11KB
search_icon.png 1KB
page3_img1.jpg 51KB
icon1.png 4KB
page5_img1.jpg 22KB
logo.png 2KB
link_arrow.png 1KB
page1_img3.jpg 17KB
static.jpg 26KB
creep2.png 11KB
page5_img5.jpg 37KB
page5_img3.jpg 30KB
page5_img2.jpg 19KB
socials.png 5KB
anim.gif 60KB
favicon.ico 5KB
page1_img2.jpg 20KB
creep1.png 16KB
icon3.png 4KB
page3_img2.jpg 39KB
page2_img1.jpg 93KB
page5_img4.jpg 28KB
prevnext.png 3KB
icon2.png 4KB
共 59 条
- 1
资源评论
2301_77550592
- 粉丝: 17
- 资源: 7165
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功