作者smileray ()
看板Programming
标题Re: [请益] 问几个问题 @@
时间Sat Apr 14 01:24:36 2007
※ [本文转录自 PHP 看板]
作者: smileray () 看板: PHP
标题: Re: [请益] 问几个问题 @@
时间: Sat Apr 14 00:34:31 2007
感谢大家的帮忙 这个问题解决了
所以又在上来问新的问题了orz 还请大家不吝指教
问题是
我现在在写一个搜寻介面
希望功能是 输入关键字串 然後在同一个页面产生搜寻结果的连结
例如输入123 这个页面的下方会出现
搜寻123的结果:
连结1
连结2
现在的问题是 按了搜寻之後什麽事情也没发生 没有错误讯息 @@
以下是程式码
<?
function EchoTitleAndHref( $Filename, $Title ) {
If ( $Title == "" ) $Title = $Filename;
echo "<LI><A HREF=\"$Filename\">$Title</A><BR>";
}
function SearchDir( $dir, $Keyword ) {
// Part I: 搜寻档案
$handle=opendir( $dir );
while ( $file = readdir($handle) ) {
if ( is_file( "$dir/$file" ) ) {
if ( strtolower(substr( "$dir/$file", -3 )) == "php" ) {
$fd = fopen("$dir/$file", "r" );
$content = fread( $fd, filesize("$dir/$file") );
$Y = strpos( $content, $Keyword );
if ( gettype($Y) == "integer" ) {
$GLOBALS["count"] = $GLOBALS["count"] + 1;
$Upcontent = strtoupper( $content );
$pos1 = strpos( $Upcontent, "<TITLE>" );
$pos2 = strpos( $Upcontent, "</TITLE>" );
$Title = "";
if ( $pos1 > 0 And $pos2 > 0 )
$Title = substr( $content, $pos1+7, $pos2 - $pos1 - 7 );
EchoTitleAndHref( "$dir/$file", $Title );
}
}
}
}
closedir($handle);
// Part II: 递回搜寻子目录
$handle=opendir( $dir );
while ( $sdir = readdir($handle) ) {
if ( is_dir("$dir/$sdir") And $sdir <> "." And $sdir <> "..") {
SearchDir( "$dir/$sdir", $Keyword );
}
}
closedir($handle);
}
?>
<HTML>
<HEAD><TITLE>搜寻引擎</TITLE></HEAD>
<BODY BGCOLOR=WHITE>
<H2>搜寻引擎<HR></H2>
<FORM Action=search.php Method=Get>
请输入欲搜寻的字串:
<INPUT Type=Text Name=Keyword>
<INPUT Type=Submit Value="搜寻">
</FORM>
<HR>
<?
if ( !empty($Keyword) ) {
echo "<H3>搜寻 $Keyword 的结果:<HR></H3>";
echo "<UL>";
$count = 0;
SearchDir( "project", $Keyword );
if ( $count == 0 ) echo "<LI>没有找到符合 \"$Keyword\" 的文件!";
echo "</UL><HR>";
}
?>
</BODY></HTML>
--
麻烦高手指教了 @@ 小的是PHP新手 请不要鞭太大力呀QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.162.49.82
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.162.49.82