[分享] 可以幫我看看PHP程式碼哪裡錯嗎
這是一個教學書上面的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 <> "..") {
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>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.33.104
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
5
22