자신의 사이트 내 검색엔진 을 만들다.
dreamweaver , , , 。 , 。 , , 。 , , 。
, , , : ? ? , ? 。 , , (<title></title>), (<bod *></body>), dreamweaver frontpage , , 。 。
,
search.htm,
<html>
<head>
<title> </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="search.php">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="36%">
<div align="center">
<input type="text" name="keyword">
</div>
</td>
<td width="64%">
<input type="submit" name="Submit" value=" ">
</td>
</tr>
</table>
</form>
</body>
</html>
,
search.php , search.htm .
<?php
//
$keyword=trim($_POST[“keyword”]);
//
if($keyword==””){
echo” ”;
exit;//
}
?>
, 。 。
, opendir,readdir, PHP Directory 。 .
<?php // function listFiles($dir){ $handle=opendir($dir); while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."){ // if(is_dir("$dir/$file")){ listFiles("$dir/$file"); } else{ // } } } } ?>
, . , $keyword, 。
<?php //$dir ,$keyword ,$array function listFiles($dir,$keyword,&$array){ $handle=opendir($dir); while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."){ if(is_dir("$dir/$file")){ listFiles("$dir/$file",$keyword,$array); } else{ // $data=fread(fopen("$dir/$file","r"),filesize("$dir/$file")); // if($file!=”search.php”){ // if(eregi("$keyword",$data)){ $array[]="$dir/$file"; } } } } } } // $array $array=array(); // listFiles(".","php",$array); // foreach($array as $value){ echo "$value"."<br>/n"; } ?>
, , 。 。
1,
if(eregi("$keyword",$data)){
$array[]="$dir/$file";
}
if(eregi("$keyword",$data)){
if(eregi("<title>(.+)</title>",$data,$m)){
$title=$m["1"];
}
else{
$title=" ";
}
$array[]="$dir/$file $title";
}
, <title>xxx</title>, xxx , ” ”.
2, 。
html , , 。 strip_tags , 。
$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
//
if($file!=”search.php”){
//
if(eregi("$keyword",$data)){
$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
if(eregi("<body([^>]+)>(.+)</body>",$data,$b)){
$body=strip_tags($b["2"]);
}
else{
$body=strip_tags($data);
}
if($file!="search.php"){
if(eregi("$keyword",$body)){
3,
foreach($array as $value){
echo "$value"."<br>/n";
}
foreach($array as $value){
//
list($filedir,$title)=split(“[ ]”,$value,”2”);
//
echo "<a href=$filedir>$value</a>"."<br>/n";
}
4
, PHP 。
set_time_limit(“600”);
, 10 。
<?php set_time_limit("600"); // $keyword=trim($_POST["keyword"]); // if($keyword==""){ echo" "; exit;// } function listFiles($dir,$keyword,&$array){ $handle=opendir($dir); while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."){ if(is_dir("$dir/$file")){ listFiles("$dir/$file",$keyword,$array); } else{ $data=fread(fopen("$dir/$file","r"),filesize("$dir/$file")); if(eregi("<body([^>]+)>(.+)</body>",$data,$b)){ $body=strip_tags($b["2"]); } else{ $body=strip_tags($data); } if($file!="search.php"){ if(eregi("$keyword",$body)){ if(eregi("<title>(.+)</title>",$data,$m)){ $title=$m["1"]; } else{ $title=" "; } $array[]="$dir/$file $title"; } } } } } } $array=array(); listFiles(".","$keyword",$array); foreach($array as $value){ // list($filedir,$title)=split("[ ]",$value,"2"); // echo "<a href=$filedir target=_blank>$title </a>"."<br>/n"; } ?>
, , , , 。 。 。
preg_match eregi, 。 , eregi.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
elasticsearchnested 삽입 대상 전체 텍스트 검색 및 정렬ES Nested 중첩 유형은 무엇입니까?Elasticsearch에는 다음과 같은 다양한 데이터 유형이 있습니다. 기본 데이터 형식:string 형식.ES 7.x에서string 형식은:text와 키워드로 업그레이드됩...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.