作者imkj (张小胖~)
看板PHP
标题可以帮我看看PHP程式码哪里错吗
时间Thu Dec 28 23:52:20 2006
这是一个教学书上面的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