Re: [分享] 可以幫我看看PHP程式碼哪裡錯嗎

看板PHP作者 (霸格尼尼)時間19年前 (2006/12/29 02:09), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《imkj (張小胖~)》之銘言: : 這是一個教學書上面的PHP程式碼 : 功能是搜尋引擎,搜尋網站裡面"VB"這個資料夾裡面的字串 : 我用來測試之後,發現有畫面,但是執行搜尋之後並沒有任何反應 : 程式碼我大概看的懂 ,不過不知道錯在哪 : 請PHP高手幫我看看哪裡有錯好嗎 謝謝 : <? : 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 )) == "htm" ) { : $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 <> "..") { 用&& != && != 注意你在寫的不是BASIC!!!! : SearchDir( "$dir/$sdir", $Keyword ); : } : } : closedir($handle); : } : ?> : <HTML> : <HEAD><TITLE>學 VB 找王國榮 -- 搜尋引擎</TITLE></HEAD> : <BODY BGCOLOR=WHITE> : <H2>學 VB 找王國榮 -- 搜尋引擎<HR></H2> : <FORM Action=search.php Method=Get> : 請輸入欲搜尋的字串: : <INPUT Type=Text Name=Keyword Value="<?echo $Keyword;?>"> : <INPUT Type=Submit Value="搜尋"> : </FORM> : <HR> : <? : if ( !empty($Keyword) ) { : echo "<H3>搜尋 $Keyword 的結果:<HR></H3>"; : echo "<UL>"; : $count = 0; : SearchDir( "vb", $Keyword ); : if ( $count == 0 ) echo "<LI>沒有找到符合 "$Keyword" 的文件!"; : echo "</UL><HR>"; : } : ?> : </BODY></HTML> -- La vida es pura paison La vida es competicion Allez, Allez, Allez!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.218.176

12/29 05:33, , 1F
咦?我以為都可以耶…
12/29 05:33, 1F

12/29 09:50, , 2F
如果只是單純說會不會work 那我的經驗是都可以用啦
12/29 09:50, 2F

12/29 09:51, , 3F
不過建議if裡面每個判斷式都用()包起來..看這樣能不能解決
12/29 09:51, 3F

12/31 12:48, , 4F
<>我是沒用過,不過AND或是or我確定可以用
12/31 12:48, 4F
文章代碼(AID): #15b0Xib5 (PHP)
文章代碼(AID): #15b0Xib5 (PHP)