Re: [請益] 問幾個問題 @@

看板Programming作者時間18年前 (2007/04/14 01:24), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 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
文章代碼(AID): #167xpLdp (Programming)
文章代碼(AID): #167xpLdp (Programming)