作者buganini (霸格尼尼)
看板PHP
标题Re: [分享] 可以帮我看看PHP程式码哪里错吗
时间Fri Dec 29 02:11:24 2006
※ 引述《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
1F:→ bcse:咦?我以为都可以耶… 12/29 05:33
2F:推 litthe:如果只是单纯说会不会work 那我的经验是都可以用啦 12/29 09:50
3F:→ litthe:不过建议if里面每个判断式都用()包起来..看这样能不能解决 12/29 09:51
4F:推 andreli:<>我是没用过,不过AND或是or我确定可以用 12/31 12:48