вообщем проблема простая, поправить и сделать не зависимый от регистра поиск, но он не делается, на пхп я никогда ничего не писал, и сайт не мой, но код почитал кой как код всего:
это на страничке блок
| Код | <FORM NAME='search' action='search.php' METHOD=post STYLE="margin:0px;"> <TR> <TD WIDTH=130><INPUT style=" padding:0px; width:118px; height:14px" CLASS='search1' NAME='str' TYPE='text' SIZE=24 VALUE='Поиск' onClick="javascript:this.value='';"></TD> <TD WIDTH=3><IMG alt="" SRC="_img/sep.gif" WIDTH=3 HEIGHT=21></TD> <TD WIDTH=21><INPUT TYPE='image' SRC="_img/searchbutton.gif" style="width:25px; height:21px" name=enter ALT="Искать" TITLE="Искать"></TD> <TD WIDTH=3><IMG alt="" SRC="_img/sep.gif" WIDTH=3 HEIGHT=21></TD> </TR> </FORM>
|
search.php, кусок
| Код | <?php error_reporting(0); session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> //бла бла бла
<?php include("init.php"); if (isset($_SESSION['str2'])) $str2=$_SESSION['str2']; if (isset($_GET['str'])) $str=$_GET['str']; if (isset($_GET['offset'])) $offset=$_GET['offset']; if (isset($_POST['str'])) $str=$_POST['str'];
function key_word($s,$key) { return ; }
function seek($dir,$base) { $path=$base; if($dir!='')$path.='/'.$dir; $handle=opendir($path); while ($file=readdir($handle)) { if($file!='.'&&$file!='..') { if(is_dir($path.'/'.$file)) seek(($dir!=''?$dir.'/'.$file:$file),$base); else do_file("$path/$file"); } } closedir($handle); }
function do_file($file) { if(strpos($file,'search.php')>0)return; global $mask_strings,$str,$context_chars,$search_results; $b=false; for($i=0;$i<count($mask_strings);$i++)if(strpos($file,$mask_strings[$i])>0)$b=true; if(!$b)return; $fd=fopen($file,"r"); $contents=fread($fd,filesize($file)); fclose($fd); $cts=strip_tags($contents); $ts=strtolower($cts); $str11=strtolower($str); //это написал Я, но толку 0 $n=strpos($ts,$str11); //менял на stripos, но толку 0 if($n===false)return; $start=$n-$context_chars; $len=$context_chars*2; if($start<0){$len+=$start;$start=0;}; if($start+$len>strlen($cts))$len-=$start+$len-strlen($cts); $s=substr($cts,$start,$len); $s1=substr($ts,$start,$len); $d1=strpos($contents,'<title'); if(!$d1)$d1=strpos($contents,'<TITLE'); if(!$d1) { $t=strpos($file,'/'); $title=substr($file,$t+1,strlen($file)-$t); //$title='untitled document'; }else { $d1=strpos($contents,'>',$d1)+1; $d2=strpos($contents,'<',$d1)-$d1; $title=substr($contents,$d1,$d2); }
$arr_t=explode($str,$s1); $qq=count($arr_t); $k=strlen($arr_t[0]); $s2=substr($s,0,$k); $k1=strlen($str); for($i=1;$i<count($arr_t);$i++) { $t=strlen($arr_t[$i]); $s2.='<span style="color: red; font-weight: bold">'.substr($s,$k,$k1).'</span>'.substr($s,$k+$k1,$t); $k+=$t+$k1; } $s=$s2;
//результат поиска///////////////////////////////////////////////////////////////////////////// $s="<h1 STYLE='font-size: 11px;'><a href='$file' STYLE='color: #545454; text-decoration: underline;'>$title</a></h1><br><h2>...{$s}...</h2><br>";
array_push($search_results,$s); }
if(!isset($offset))$offset=0; if(isset($str)) { session_register("str2"); $_SESSION['str2']=$str;
}else $str=$str2; $search_results=array(); $str=strtolower($str); //echo(strlen($str)); if(strlen($str)!=0||!isset($str))seek('',$root_dir);
//ничего не найдено//////////////////////////////////////////////////////////////////////////// if(count($search_results)==0)echo('<TR ALIGN=center><TD><h1 aligh="center">По вашему запросу ничего не найдено</h1></TD></TR>'); else
{
//врхний блок найденных страниц (1-10 11-20)/////////////////////////////////////////////////// echo('<TR ALIGN=center><TD><H1 STYLE="font-size: 11px;">'); $num=floor((count($search_results)+0.0)/$results_per_page); for($i=0;$i<$num;$i++) if($offset==$i*$results_per_page) echo('<a href="search.php?offset='.($i*$results_per_page).'" STYLE="color: #950137; text-decoration: none;">'. ($i*$results_per_page+1).'-'.(($i+1)*$results_per_page).'</A> ');else echo('<a href="search.php?offset='.($i*$results_per_page).'" STYLE="color: #545454; text-decoration: underline;">'. ($i*$results_per_page+1).'-'.(($i+1)*$results_per_page).'</A> ');
$num1=count($search_results)%$results_per_page; if($num1!=0) { if($offset==$num*$results_per_page)
//исправь echo('<a href="search.php?offset='.($num*$results_per_page).'" STYLE="color: #950137; text-decoration: none;">'. ($num*$results_per_page+1).'-'.($num*$results_per_page+$num1).'</a></TD></TR>');else echo('<a href="search.php?offset='.($num*$results_per_page).'" STYLE="color: #545454; text-decoration: underline;">'. ($num*$results_per_page+1).'-'.($num*$results_per_page+$num1).'</a></TD></TR>'); } echo('</H1></TD></TR>');
echo('<TR><TD>'); for($i=0;$i<$results_per_page;$i++)echo($search_results[$i+$offset]); echo('</TD></TR>');
//нижний блок найденных страниц (точно как верхний)///////////////////////////////////////////// echo('<TR ALIGN=center><TD><h1 STYLE="font-size: 11px;">'); $num=floor((count($search_results)+0.0)/$results_per_page); for($i=0;$i<$num;$i++) if($offset==$i*$results_per_page) echo('<a href="search.php?offset='.($i*$results_per_page).'" STYLE="color: #950137; text-decoration: none;">'. ($i*$results_per_page+1).'-'.(($i+1)*$results_per_page).'</A> ');else echo('<a href="search.php?offset='.($i*$results_per_page).'" STYLE="color: #545454; text-decoration: underline;">'. ($i*$results_per_page+1).'-'.(($i+1)*$results_per_page).'</A> ');
$num1=count($search_results)%$results_per_page; if($num1!=0) { if($offset==$num*$results_per_page)
//исправь echo('<a href="search.php?offset='.($num*$results_per_page).'" STYLE="color: #950137; text-decoration: none;">'. ($num*$results_per_page+1).'-'.($num*$results_per_page+$num1).'</a></TD></TR>');else echo('<a href="search.php?offset='.($num*$results_per_page).'" STYLE="color: #545454; text-decoration: underline;">'. ($num*$results_per_page+1).'-'.($num*$results_per_page+$num1).'</a></TD></TR>'); } echo('</h1>'); }
?>
|
init.php
| Код | <?php //директория для поиска (для текущей='.') $root_dir='.';
//маска файлов поиска (например $mask_strings=array('htm','txt','asp') $mask_strings=array('htm','html','txt');
//количество выводимых на странице результатов $results_per_page=10;
//количество выводимых символов слева и справа от ключевого слова $context_chars=200; ?>
|
$str11=strtolower($str); //это написал Я, но толку 0 $n=strpos($ts,$str11); //менял на stripos, но толку 0
изначально думал ща на stripos поменяю, и буду в шоколаде, однако весь день экспериментировал, жижа получилась похожая по цвету и консистенции, но это не шоколад
Помогите кто чем может, наседает директор |