PHP实用小程序(七)

//用COOKIE保存投票人的投票记录
    if($vote && !$already_voted) SetCookie("already_voted","1");
?>


简易投票系统



简易投票系统-学习PHP 4.0容易吗?

#FFFFFF width="60%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
$PHP_SELF?>" method="post" name="frmVote">
添加一个投票类别:

//连接数据库 mysql_connect("localhost","root",""); $mysqldb="test"; if($newvoteitem) { //添加新的投票项 if(!mysql_db_query($mysqldb,"insert into vote values ('$newvoteitem',0)")) { echo "添加出错!
"; } } //用COOKIE保存投票人的投票记录 if($vote && $already_voted) { echo "请您不要重复投票,谢谢!

\n"; } else if($vote) { if(!mysql_db_query($mysqldb,"update vote set votes=votes+1 where name='$vote'")) { echo "投票出错!
"; } } //计算总投票数 $result=mysql_db_query($mysqldb,"select sum(votes) as sum from vote"); if($result) { $sum=(int) mysql_result($result,0,"sum"); mysql_free_result($result); } //读出投票项数据 $result=mysql_db_query($mysqldb,"select * from vote order by votes DESC"); ?> #FFFFFF width="90%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">//循环读出投票项while($row=mysql_fetch_row($result)) { //计算百分比$per=(int)(100*$row[1]/$sum); ?> } //释放结果集mysql_free_result($result); ?>
投票 选项 票数/比例
$row[0]?>"> echo $row[0]?> echo $row[1]?>$per?>">echo $per?>

require("config.php");
    $sqldo="select count(*) as title from $mytable where sub_id<1";
    $result=mysql_query($sqldo);
    $message_count=mysql_result($result,0,"title");
?>
留言总数:echo $message_count?> | 看留言    
if ($doadd) { $name=htmlspecialchars($name); $email=htmlspecialchars($email); $comefrom=htmlspecialchars($comefrom); $homepage=htmlspecialchars($homepage); $icq=htmlspecialchars($icq); $oicq=htmlspecialchars($oicq); $image=htmlspecialchars($image); $comment=htmlspecialchars($comment); if ($name&&$comment) { $add_time=date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s"); $result=mysql_query("insert into $mytable (sub_id,name,email,comefrom,homepage,icq,oicq,image,comment,password,add_time) values ('$sub_id','$name','$email','$comefrom','$homepage','$icq','$oicq','$image','$comment','$password','$add_time')"); if ($notify) { $message="$comment\n\n$name $email\n\n$add_time"; mail($admin_email, "有新的留言: ".$name, $message, "From: ".$email."\nReply-To: ".$email."\nX-Mailer: PHP/" . phpversion()); } echo "

您的留言发送成功,谢谢!查看留言请返回

\n"; } else { echo "

姓名和内容必须填写!返回

\n"; } } else { if ($reply&&$recid) { echo "

回复留言

"; $sub_id="$recid\">"; } else { echo "

填写留言

"; } echo "
姓名: $sub_id 电子邮件:
来自: 主页地址:
OICQ:

表情: "; $con=1; while ( list( $key, $val ) = each( $images ) ) { $checked=""; if ($con==1) { $checked=" checked"; $con=0; } echo "$key\" name=\"image\"$checked>$imgdir/$key\" alt=\"$val\"> "; } echo "

\n

留言:

"; } ?>



PHP4.0 +<span style="color:#008080;">MYSQL</span> 留言本



PHP4.0+MYSQL 留言本

$dbuser=mysql_connect('localhost','root',''); $mydb=mysql_select_db('test',$dbuser); $mytable="guestbook"; // 表名 $page_size=8; $notify=1; $imgdir="images"; $images=array( "say.gif" => "随便说说", "happy.gif" => "高兴", "sad.gif" => "悲伤", "toohappy.gif" => "大笑", "wilk.gif" => "眨眼", "warning.gif" => "警告", "question.gif" => "问题", "reply.gif" => "回答", "attention.gif" => "注意", "agree.gif" => "同意", "other.gif" => "号外" ); ?>
require("config.php");
    if (!$page)
    {
        $page=1;
    }
    $sqldo="select count(*) as title from $mytable where sub_id<1";
    $result=mysql_query($sqldo);
    $message_count=mysql_result($result,0,"title");
    $page_count=ceil($message_count/$page_size);
    $offset=($page-1)*$page_size;
    $sqldo="select * from $mytable where sub_id<1 order by id desc limit $offset, $page_size";
    $result=mysql_query($sqldo);
?>
留言总数:echo $message_count?> | 写留言    

if($result) { while($myrow=mysql_fetch_array($result)) { listtopic($myrow,"70%",1); $sqldo2="select * from $mytable where sub_id=$myrow[id] order by add_time"; $result2=mysql_query($sqldo2); if($result2) { $rows2=mysql_num_rows($result2); if($rows2) { ?>

while($myrow2=mysql_fetch_array($result2)) { listtopic($myrow2,"100%",0); echo "
"; } ?>
} } echo "
"; } $prev_page=$page-1; $next_page=$page+1; echo "

| "; if ($page<=1){ echo "第一页 | "; } else{ echo "第一页 | "; } if ($prev_page<1){ echo "上一页 | "; } else{ echo "上一页 | "; } if ($next_page>$page_count){ echo "下一页 | "; } else{ echo "下一页 | "; } if ($page>=$page_count){ echo "最后一页 |

\n"; } else{ echo "最后一页 |

\n"; } } function listtopic($myrow,$this_table_width,$is_reply) { global $imgdir; $comment=nl2br($myrow[comment]); if ($myrow[email]) { $line1_left="$imgdir\\$myrow[image]\"> $myrow[email]\">$myrow[name]"; } else { $line1_left="$imgdir\\$myrow[image]\"> $myrow[name]"; } if ($myrow[comefrom]) { $line1_left .= "  来自: $myrow[comefrom]"; } else { $line1_right=""; } if ($myrow[oicq]) { $line1_right .= " $imgdir\\oicq.gif\" alt=\"OICQ:$myrow[oicq]\">"; } if ($myrow[homepage]) { $line1_right .= " $myrow[homepage]\" target=\"_blank\">$imgdir\\homepage.gif\" alt=\"主页:$myrow[homepage]\">"; } if ($is_reply) { $toolsbar="$myrow[id]\" $table_head_bodystyle>回复 "; } $toolsbar .= "修改 删除 "; ?> $this_table_width?>" align="center"> } ?>
// 本例来自与ZEND网站,由HUNTE整理 

if($action1){ 
//如果文件上传,进行处理
?> 
 
 
多文件上传 
 
 

 

文件上传处理

set_time_limit(60); // 以确保较大文件上传 $path1 = dirname($PATH_TRANSLATED)."/upload/"; //输出上传路径; //print $path1."
"; // assign our path in a form PHP for Windows understands
for($i=1;$i<3;$i++) { $temp1="file".$i; $temp2="file".$i."_name"; $source=$$temp1; $source_name=$$temp2; // print $temp."=".$$temp."
"; //print $file1_name; //print $file2_name; //exit; //***************** //$source = $file1; //$source_name = $file1_name; //print $source."
"; //print $source_name; //exit;
if(($source <> "none")&&($source <> "")) { // see if the file exists; non-existing file has name of "none" if($error1 <> 1) { // no need to copy a file if directory not write-enabled $dest = $path1.$source_name; // append file name to our path if(copy($source,$dest)){ // copy the file from the temp directory to the upload directory, and test for success echo "$source has been uploaded
\n"; $imagesize = getimagesize($dest); switch($imagesize[2]) { case 0: echo "
Image is a unknown
"; //unlink($dest); exit; case 1: echo "
Image is a GIF
"; echo "$dest has a width of $imagesize[0]
"; echo "$dest has a height of $imagesize[1]
"; $newname = $path1; $newname .=$i.time() . ".gif"; if(copy($dest,$newname)) { //echo "
GIF Rename Successful from $dest to $newname";
}else { //echo "
GIF Rename Unsuccessful";
} //unlink ($dest); break; case 2: echo "
Image is a JPG
"; echo "$dest has a width of $imagesize[0]
"; echo "$dest has a height of $imagesize[1]
"; $newname = $path1; $newname .=$i.time() . ".jpg"; if(copy($dest,$newname)) { //echo "
JPG Rename Successful from $dest to $newname";
}else { //echo "
JPG Rename Unsuccessful";
} //unlink ($dest); break; case 3: echo "
Image is a PNG
"; echo "$dest has a width of $imagesize[0]
"; echo "$dest has a height of $imagesize[1]
"; $newname = $path1; $newname .=time() . ".png"; if(copy($dest,$newname)) { //echo "
PNG Rename Successful from $dest to $newname";
}else { //echo "
PNG Rename Unsuccessful";
} //unlink ($dest); break; } }else { echo "Upload directory not write-enabled\n"; // you need to write-enable the upload directory $error1 = 1; // set flag } } //unlink($source); // delete the file from the temp directory } ?> $newname)?>"> } //end for ?>
Back

} else { ?> 多文件上传

File Upload

If your browser is upload-enabled, you will see "Browse&quot; (Netscape, Internet Explorer) or ". . ." (Opera) buttons below. Use them to select file(s) to upload, then click the "Upload&quot; button. After the files have been uploaded, you will see a results screen.
File 1:
File 2:

} ?>
php 
//计数器 
//本计数器无需数据库支持。 
//说明: 
// $five,$four等标量表示零的个数,放在数字前构成6位 
//的来访者数目。当然,如果你的网站 
//浏览量十分巨大,你可以添加$six,$seven等等构成更大的数字显 
//示来访者的数目。 
function Counter() { 
$five="00000"; 
$four="0000"; 
$three="000"; 
$two="00"; 
$one="0"; 
$counter="counternumber.dat"; //存放访客数目的文件.dat格式 
if (!file_exists($counter)) //判断文件是否存在,如果不存在以写方式建立一个文件 
{ 
$counter=fopen($counter,"w"); 
fputs($counter,"0"); 
fclose($counter); 
} 
else 
{ 
$num=file($counter,"r"); //如果文件存在则读出文件,并加1 
$num[0]+=1; 
if($num[0]<10){ //判断数字的大小,如果小于100000根据不同情况在前面 
print "$five"."$num[0]"; //加上不同个数的0,为了凑够6位。 
}elseif($num[0]<100){ 
print "$four"."$num[0]"; 
}elseif($num[0]<1000){ 
print "$three"."$num[0]"; 
}elseif($num[0]<10000){ 
print "$two"."$num[0]"; 
}elseif($num[0]<100000){ 
print "$one"."$num[0]"; 
}else{ 
print "$num[0]"; 
} } 
$fp=fopen($counter,"w"); //以写入文件方式打开文件 
fputs($fp,"$num[0]"); //将加过1的数字放入文件中 
fclose($fp); //关闭文件 
} 


?> 

 
 
 
 
 
 
 
 
 
 
 
highlight_file($filename); //高亮显示文件代码 
?> 

require ("phplist.inc"); 
if ($rootpath=="") {$rootpath=$htmlroot;} 
function filelist($pathname){ //遍历所有的文件和目录,$pathnam为起始目录,$searchs为搜索关键字 
global $htmlroot; 
if (eregi("[/][.][.]$",$pathname)) { 
$temp=split("[/]",$pathname); 
$pathname=""; 
for ($tt=1;$tt<(count($temp)-2);$tt++) 
$pathname=$pathname."/".$temp[$tt]; 
} 
echo $pathname."
"; $handle=opendir($pathname); //打开目录 if (@chdir($pathname)) { //cd 进入目录,若无权限则不进入 $file = readdir($handle); //读出所有当前目录下的元素名,第一次读出为‘。’,指上层目录 while ($file = readdir($handle)) { //若有元素就进行以下处理 $fname=$pathname."/".$file; //将元素名与当前目录名结合组成完整的文件名,并赋值给$fname if ((is_file($file)) and (ereg("\.php[3]{0,1}$",$file) or ereg("\.htm[l]{0,1}$",$file))) //判断是否为文件并且是否以.php和.php3结尾 { $temppp=split($htmlroot,$fname); echo "$temppp[1]>".$file."   ".filesize($file)."bytes      $fname>源文件
"; //findinfile($fname,$searchs); //调用findinfile函数 } elseif (is_dir($fname)) { //判断是否为目录 linkres($fname); //filelist($fname,$searchs);} //递归调用filelist函数 } } chdir(".."); //结束当前递归,返回上层 } closedir($handle); //关闭当前目录读取 } // function linkres($filename){ $tpath=split("/web/html",$filename); $turepath=$tpath[1]; ereg("[^\\\/\~]{0,}$",$filename,$res); //$ft=filetitle($filename); //if ($ft=="") $ft="无标题"; echo "$filename>".$res[0]."   <dir>
"; } // filelist($rootpath); ?>


简易聊天室


echo $line1_left?> echo $line1_right?> 
echo $comment?>
留言时间:echo $myrow[add_time]?> echo $toolsbar?>
/*If you have ICQ List you vin here.*/ $uin = "20559508"; /*Dat file name. Make sure it is in the same folder*/ $talk_back_ok = "msg.txt"; /*Webmasters Image Location(put url not path)*/ $webmaster_image = "kmoo.gif"; /*Webmasters Name*/ $webmaster_name = "root"; /*Webmasters Password*/ $pass = ""; /*messages displayed*/ $help_lenght = 20; /*Home Long can the lake each message*/ $max_single_msg_lenght = 100000; $max_file_size = $help_lenght * $max_single_msg_lenght; ?>
$person = str_replace ("\n"," ", $person); $person = str_replace ("<", " ", $person); $person = str_replace (">", " ", $person); $person = stripslashes ($person); ?> /* check if file size is over maximum*/$file_size= filesize($talk_back); if ($file_size > $max_file_size) { $lines = file($talk_back_ok); $a = count($lines); $u = $a - $help_lenght; for($i = $a; $i >= $u ;$i--){ $msg_old = $lines[$i] . $msg_old; } $deleted = unlink($talk_back_ok); $fp = fopen($talk_back_ok, "a+"); $fw = fwrite($fp, $msg_old); fclose($fp); } $msg = str_replace ("\n"," ", $message); $msg = str_replace ("\n"," ", $message); $msg = str_replace ("<", " ", $msg); $msg = str_replace (">", " ", $msg); $msg = stripslashes ($msg); if($person == $pass) { $sign = (" $webmaster_name"); } else { $sign = ($person); } if ($msg != "" && $person != ""){ $time = gmDate("h:i"); $fp = fopen($talk_back_ok, "a+"); $fw = fwrite($fp, "\n"); fclose($fp); } ?>
妮称:$person; ?>">
$sign :$time : $msg


<span style="color:#000000;">
聊天室
</span>



/*Dat file name. Make sure it is in the same folder*/
$talk_back_ok = "msg.txt";
/*Webmasters Name*/
/*Webmasters Password*/
/*messages displayed*/
$help_lenght = 15;
/*Home Long can the lake each message*/
$max_single_msg_lenght = 100000;
$max_file_size = $help_lenght * $max_single_msg_lenght;
?>
/* check if file size is over maximum*/

$file_size= filesize($talk_back);

            
if ($file_size > $max_file_size) {

$lines = file($talk_back_ok);

$a = count($lines);

$u = $a - $help_lenght;
for($i = $a; $i >= $u ;$i--){
        $msg_old =  $lines[$i] . $msg_old;
    }
$deleted = unlink($talk_back_ok);
$fp = fopen($talk_back_ok, "a+");
$fw = fwrite($fp, $msg_old);
fclose($fp);
}

$msg = str_replace ("\n"," ", $message);

$msg = str_replace ("\n"," ", $message);
$msg = str_replace ("<", " ", $msg);
$msg = str_replace (">", " ", $msg);
$msg = stripslashes ($msg);

if($person == $pass)
   {
   $sign = (" $webmaster_name");
   }
   else
   {
   $sign = ($person);
   }
   
if ($msg != "" && $person != ""){
$time = gmDate("h:i");
$fp = fopen($talk_back_ok, "a+");
$fw = fwrite($fp, "\n $sign :$time : $msg
"); fclose($fp); } $lines = file($talk_back_ok); $a = count($lines); $u = $a - $help_lenght; for($i = $a; $i >= $u ;$i--){ echo $lines[$i]; } ?>

<span style="color:#000000;">
在线聊天
</span>


    
    







$adminpsd   = "xlj";            //管理密码
    $newsbook   = "./data/newsbook.txt";    //新闻存放的文件
    $refreshbook    = "./data/refreshbook.txt"; //防刷新的文件
    $line_max   = 5;                //显示的最大纪录数
    $dot_pic    = "dot2.gif";           //图片
?>
require "config.php"; ?>




简单的新闻公告栏



$line_array=file($newsbook); $linenum=count($line_array); if($table!=1) { ?> } $i=0; while($i<$linenum && $i<$line_max) { $line="$line_array[$i]\n"; print "$line"; $i++; } if($table!=1) { ?>
} ?>
require "config.php";?>
if($password !=$adminpsd)
    {
        print "管理密码错!
";exit; } $title=ereg_replace("\r\n",'
',$title); $addline="$dot_pic>$title"; //查数据文件是否存在 if(!file_exists($refreshbook)) { $f = fopen("$refreshbook","w"); fclose($f); } if(!file_exists($newsbook)) { $f = fopen("$newsbook","w"); fclose($f); } $f = fopen("$refreshbook","r"); $line_has1 = fread($f,filesize("$refreshbook")); fclose($f); if($addline==$line_has1) { print "数据已经登录,请勿刷新!
"; exit; } else { $f = fopen("$refreshbook","w"); fwrite($f,"$addline"); fclose($f); } //先读出原有数据 $f = fopen("$newsbook","r"); $line_has = fread($f,filesize("$newsbook")); fclose($f); //用覆盖方式(w)将原数据及新数据写回去 $f = fopen("$newsbook","w"); fwrite($f,"$addline\n"); #写进去,要加 \n fwrite($f,"$line_has"); fclose($f); print "录入完成,谢谢!
";exit; ?>


PHP目录树演示


#eeffee link=#339933>

PHP目录树演示

php /*********************************************/ /* PHP目录树演示 */ /*********************************************/ /*********************************************/ /* 文件结构 */ /*********************************************/ $treefile = "demomenu.txt"; /*********************************************/ /* 包函树节点 */ /*********************************************/ require "treemenu.inc"; ?>
$file=file("record.txt");
    $intt=sizeof($file);
    $file2=array();
    $cont=$intt/3;

    $conttj=1;
    for($i=0;$i<$intt;$i=$i+3)
    {
        if($file[$i] == $id."\n")
        {
            $k=$i;
            for($j=$conttj;$j<=$cont;$j++)
            {
                $file[$k]=$file[$k+3];
                $file[$k+1]=$file[$k+4];
                $file[$k+2]=$file[$k+5];
                $k=$k+3;
            }
            $conttj=$conttj+1;
        }
    }
    $intt2=sizeof($file);
    $f2=fopen("record.txt","w+");
    for($i=0;$i<$intt2;$i++)
    {
        fputs($f2,$file[$i]);
    }
?>


访客留言本



false cols=300,* frameBorder=0 frameSpacing=0>


<body>
</body>


View Raw Code?


访客留言本







#ffffff>
#ffffff>

姓名 class=stedit name=name size=24>
信箱 class=stedit name=email size=24 value=@>
主页 class=stedit name=url size=24 value=http://>
主题 class=stedit name=title size=24>
选项
内 容

<IMG border=0 height=5 src="" width=1>
class=stedit name=Submit type=submit value=" 提 交 "> class=stedit name=Submit2 type=reset value=" 清 除 ">

if($type=="add")
    {
        $file=file("record.txt");
        $intt=sizeof($file);
        $tx=$file[0]+1;

        $f = fopen("record.txt","r+");
        $msg = fread($f,filesize("record.txt")) ;
        fclose($f);

        $f = fopen("record.txt","r+");
        $text=$txt;
        $text=htmlspecialchars($text);
        $text=ereg_replace("\r\n","
",$text); $text=ereg_replace("\r","
",$text); $text=$text."\n"; $t = date(Y年m月d日H时i分); $line1=$name."||".$email."||".$url."||".$sex."||".$mind."||".$title."||".$t."\n"; if(str_replace("\n","",$file[2])!=trim($text)) { fputs($f,$tx."\n"); fputs($f,$line1); fputs($f,$text); fputs($f,$msg); fclose($f);} } ?> $filename="record.txt"; $file=file($filename); $intt=sizeof($file); $pagesize=3; $pagecount=round(($intt/3)/$pagesize) ; if($pagesize*$pagecount<$intt/3) { $pagecount++; } if($pagepage2) { $page=$pagepage2-1; if($pagepage2>$pagecount) { $page=$pagecount-1;} if($pagepage2<1) { $page=0;} } $pagecount2=$pagecount-1; $page2=$page+1; $pp=$page*$pagesize*3; $pp2=$pp+$pagesize*3; $nextpage=$page+1; $prevpage=$page-1; ?> #000000 bgColor=#f5f5f5 link=#000000 text=#000000 vLink=#999999>
#ffffff>
目前共有echo $intt/3;?>条留言 if ($page != 0){ ?> echo $prevpage?>>后页 if ($page != $pagecount2) {?> echo $nextpage?>>后页  第<font face=Tahoma>echo $page2."/".$pagecount; ?>
class=stbtm name=pagepage2 size=2> name=Submit2 src="images/go2.gif" type=image value=跳转>
for($i=$pp;$i<$pp2;$i=$i+3) { if($i<$intt) { $tp=explode("||",$file[$i+1]); ?>

$tp[1];?>">给我来信!$tp[3].$tp[4]?>.gif" > $tp[1];?>"><font size=2>echo $tp[0];?> $tp[2];?>" target=_blank> size=1>echo $tp[2];?>
$tp[2];?>" target=_blank>
echo $tp[6];?>
留言主题:echo $tp[5];?>
#f5f5f5 colspan="2">
echo $file[$i+2];?>

} } ?>

#ffffff>
目前共有echo $intt/3;?>条留言 if ($page != 0){ ?> echo $prevpage?>>后页 if ($page != $pagecount2) {?> echo $nextpage?>>后页  第<font face=Tahoma>echo $page2."/".$pagecount; ?>
class=stbtm name=pagepage2 size=2> name=Submit22 src="images/go2.gif" type=image value=跳转>
//-----------------------------------------------------------------
// 安装说明:
// 1,把97-1.php(就是本文件)加到一个PHP页中。
// 2,设置好选票数据文件和选票IP记录文件的路径及文件名,并设置属性为666(保证可读写)。
// 安装完成了(太简单拉^_^)
//-----------------------------------------------------------------
// 选票数据文件的格式说明:
// 该文件只有1行,共分成11段,每段都用“|”分隔,内容如下(“[]”内为说明如该段不需要有内容,则需将其空出来。)
// [选票标题]|[选择A]|[选择A的得票数]|[选择B]|[选择B的得票数]|[选择C]|[选择C的得票数]|[选择D]|[选择D的得票数]|[选择E]|[选择E的得票数]
//-----------------------------------------------------------------
// 选票IP记录文件的格式说明:
// 这个文件不需要编辑,只是为了防止某些人重复投票而做的IP判断过滤。
// 文件的格式就是每个IP值占一行,有多少人投票就有多少行。
// 该文件的初始状态就是为空(0字节)。
//-----------------------------------------------------------------
  $file="97_data.txt"; /*选票数据文件*/
  $fd=fopen("$file","r");
  $fd_data=fread($fd,filesize($file));
  fclose($fd);
  list($votez_name,$vote1_name,$vote1_counter,$vote2_name,$vote2_counter,$vote3_name,$vote3_counter,$vote4_name,$vote4_counter,$vote5_name,$vote5_counter)=split("\|",$fd_data);
  $votez_counter=$vote1_counter+$vote2_counter+$vote3_counter+$vote4_counter+$vote5_counter;
  if($vote1_counter>0){$vote1_countera=substr($vote1_counter/$votez_counter*100,0,4)."%";}else{$vote1_countera="0.00%";}
  if($vote2_counter>0){$vote2_countera=substr($vote2_counter/$votez_counter*100,0,4)."%";}else{$vote2_countera="0.00%";}
  if($vote3_counter>0){$vote3_countera=substr($vote3_counter/$votez_counter*100,0,4)."%";}else{$vote3_countera="0.00%";}
  if($vote4_counter>0){$vote4_countera=substr($vote4_counter/$votez_counter*100,0,4)."%";}else{$vote4_countera="0.00%";}
  if($vote5_counter>0){$vote5_countera=substr($vote5_counter/$votez_counter*100,0,4)."%";}else{$vote5_countera="0.00%";}
  echo "
$vote1_counter&vote2=$vote2_counter&vote3=$vote3_counter&vote4=$vote4_counter&vote5=$vote5_counter>
$votez_name
总票数:
$votez_counter
选择A:$vote1_name
$vote1_counter票|$vote1_countera
选择B:$vote2_name
$vote2_counter票|$vote2_countera
选择C:$vote3_name
$vote3_counter票|$vote3_countera
选择D:$vote4_name
$vote4_counter票|$vote4_countera
选择E:$vote5_name
$vote5_counter票|$vote5_countera

"; //----------------------------------------------------------------- ?>
$file1="97_data.txt"; /*选票数据文件*/
  $file2="97_ip.txt"; /*选票IP记录文件*/
  
//---------------------------------------------------
  $this_ip=getenv("REMOTE_ADDR")."\n";
  $fd2=fopen("$file2","r");
  $fd_data2=fread($fd2,filesize($file2));
  fclose($fd2);
  if(!ereg($this_ip,$fd_data2)){
    $fd2=fopen("$file2","a");
    $fd_write2=fwrite($fd2,$this_ip,strlen($this_ip));
    fclose($fd2);
  //---------------------------------------------------
    $fd1=fopen("$file1","r");
    $fd_data1=fread($fd1,filesize($file1));
    fclose($fd1);
    list($votez_name,$vote1_name,$vote1_counter,$vote2_name,$vote2_counter,$vote3_name,$vote3_counter,$vote4_name,$vote4_counter,$vote5_name,$vote5_counter)=split("\|",$fd_data1);
  //---------------------------------------------------
 
    if(!empty($vote)){
           if($vote==1 && !empty($vote1_name)){$vote1_counter++;
      }elseif($vote==2 && !empty($vote2_name)){$vote2_counter++;
      }elseif($vote==3 && !empty($vote3_name)){$vote3_counter++;
      }elseif($vote==4 && !empty($vote4_name)){$vote4_counter++;
      }elseif($vote==5 && !empty($vote5_name)){$vote5_counter++;
      }
      $fd_data1="$votez_name|$vote1_name|$vote1_counter|$vote2_name|$vote2_counter|$vote3_name|$vote3_counter|$vote4_name|$vote4_counter|$vote5_name|$vote5_counter";
      $fd1=fopen("$file1","w");
      $fd_write1=fwrite($fd1,$fd_data1,strlen($fd_data1));
      fclose($fd1);
    }
  }
//---------------------------------------------------
?>

谢谢您对本站的支持,三秒后将自动返回……

Header("Content-type: image/gif");
  /**************************************/
  /** 程序:选票统计                   **/
  /** 文件:emi_vote.php               **/
  /** 日期:2000/01/25                 **/
  /** 版本:v1.0                       **/
  /** 作者:emildy                     **/
  /** 主页:http://www.e-mi.net        **/
  /** 请勿删除此段版权信息  谢谢合作   **/
  /**************************************/
  $votez=$vote1+$vote2+$vote3+$vote4+$vote5;
  if($vote1>0){$vote1a=$vote1/$votez*360;}else{$vote1a=0;}
  if($vote2>0){$vote2a=$vote2/$votez*360;}else{$vote2a=0;}
  if($vote3>0){$vote3a=$vote3/$votez*360;}else{$vote3a=0;}
  if($vote4>0){$vote4a=$vote4/$votez*360;}else{$vote4a=0;}
  if($vote5>0){$vote5a=$vote5/$votez*360;}else{$vote5a=0;}
  $img_output=ImageCreate(88,70);
  $color0a=imagecolorallocate($img_output,255,255,255); /**/
  $color0b=imagecolorallocate($img_output,  0,  0,  0); /**/
  $color1a=imagecolorallocate($img_output,255,  0,  0); /*红a*/
  $color1b=imagecolorallocate($img_output,200,  0,  0); /*红b*/
  $color2a=imagecolorallocate($img_output,255,128, 64); /*橙a*/
  $color2b=imagecolorallocate($img_output,198, 64,  0); /*橙b*/
  $color3a=imagecolorallocate($img_output,255,255,  0); /*黄a*/
  $color3b=imagecolorallocate($img_output,200,200,  0); /*黄b*/
  $color4a=imagecolorallocate($img_output,133,248, 18); /*绿a*/
  $color4b=imagecolorallocate($img_output,  0,200,  0); /*绿b*/
  $color5a=imagecolorallocate($img_output,  0,  0,255); /*蓝a*/
  $color5b=imagecolorallocate($img_output,  0,  0,200); /*蓝b*/
  imagecolortransparent($img_output,$color0a); /*白色为透明色*/

  $picture_x=43; /*饼图的中心点-X*/
  $picture_y=30; /*饼图的中心点-Y*/
  $picture_w=80; /*饼图的中心点-w*/
  $picture_h=40; /*饼图的中心点-h*/

  for($temp_a=$picture_y+11;$temp_a>$picture_y;$temp_a--){
    if($vote5>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$temp_a,$temp_b,$temp_b*5/8,0                              ,$vote5a                        ,$color5b);}}
    if($vote4>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$temp_a,$temp_b,$temp_b*5/8,$vote5a                        ,$vote5a+$vote4a                ,$color4b);}}
    if($vote3>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$temp_a,$temp_b,$temp_b*5/8,$vote5a+$vote4a                ,$vote5a+$vote4a+$vote3a        ,$color3b);}}
    if($vote2>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$temp_a,$temp_b,$temp_b*5/8,$vote5a+$vote4a+$vote3a        ,$vote5a+$vote4a+$vote3a+$vote2a,$color2b);}}
    if($vote1>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$temp_a,$temp_b,$temp_b*5/8,$vote5a+$vote4a+$vote3a+$vote2a,360                            ,$color1b);}}
  }
  if($vote5>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$picture_y,$temp_b,$temp_b*5/8,0                              ,$vote5a                        ,$color5a);}}
  if($vote4>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$picture_y,$temp_b,$temp_b*5/8,$vote5a                        ,$vote5a+$vote4a                ,$color4a);}}
  if($vote3>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$picture_y,$temp_b,$temp_b*5/8,$vote5a+$vote4a                ,$vote5a+$vote4a+$vote3a        ,$color3a);}}
  if($vote2>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$picture_y,$temp_b,$temp_b*5/8,$vote5a+$vote4a+$vote3a        ,$vote5a+$vote4a+$vote3a+$vote2a,$color2a);}}
  if($vote1>0){for($temp_b=$picture_w;$temp_b>0;$temp_b--){imagearc($img_output,$picture_x,$picture_y,$temp_b,$temp_b*5/8,$vote5a+$vote4a+$vote3a+$vote2a,360                            ,$color1a);}}

  ImageGif($img_output);
  ImageDestory($img_output);
?>
View Raw Code?
//世纪万年历
#这是唯一的设置-请输入php文件的位置
$file="http://192.168.1.168/php/rl/s2m.php";
//#农历每月的天数
$everymonth=array(
0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1),
1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2),
2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3),
3=>array(5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4),
4=>array(0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5),
5=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6),
6=>array(4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7),
7=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8),
8=>array(0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9),
9=>array(2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10),
10=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11),
11=>array(6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12),
12=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1),
13=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2),
14=>array(5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3),
15=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4),
16=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5),
17=>array(2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6),
18=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7),
19=>array(7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8),
20=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9),
21=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10),
22=>array(5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11),
23=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12),
24=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1),
25=>array(4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2),
26=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3),
27=>array(0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4),
28=>array(2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5),
29=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6),
30=>array(6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7),
31=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8),
32=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9),
33=>array(5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10),
34=>array(0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11),
35=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12),
36=>array(3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1),
37=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2),
38=>array(7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3),
39=>array(0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4),
40=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5),
41=>array(6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6),
42=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7),
43=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8),
44=>array(4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9),
45=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10),
46=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11),
47=>array(2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12),
48=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1),
49=>array(7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2),
50=>array(0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3),
51=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4),
52=>array(5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5),
53=>array(0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6),
54=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7),
55=>array(3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8),
56=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9),
57=>array(8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10),
58=>array(0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11),
59=>array(0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12),
60=>array(6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1),
61=>array(0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2),
62=>array(0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3),
63=>array(4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4),
64=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5),
65=>array(0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6),
66=>array(3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7),
67=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8),
68=>array(7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9),
69=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10),
70=>array(0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11),
71=>array(5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12),
72=>array(0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1),
73=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2),
74=>array(4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3),
75=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4),
76=>array(8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5),
77=>array(0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6),
78=>array(0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7),
79=>array(6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8),
80=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9),
81=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10),
82=>array(4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11),
83=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12),
84=>array(10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1),
85=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2),
86=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3),
87=>array(6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4),
88=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5),
89=>array(0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6),
90=>array(5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7),
91=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8),
92=>array(0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9),
93=>array(3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10),
94=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11),
95=>array(8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12),
96=>array(0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1),
97=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2),
98=>array(5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3),
99=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4),
100=>array(0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5),
101=>array(4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6),
102=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7),
103=>array(0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8),
104=>array(2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9),
105=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10),
106=>array(7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11),
107=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12),
108=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1),
109=>array(5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2),
110=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3),
111=>array(0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4),
112=>array(4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5),
113=>array(0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6),
114=>array(9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7),
115=>array(0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8),
116=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9),
117=>array(6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10),
118=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11),
119=>array(0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12),
120=>array(4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1)
);
##############################
#农历天干
$mten=array("null","甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
#农历地支
$mtwelve=array("null","子(鼠)","丑(牛)","寅(虎)","卯(兔)","辰(龙)",
               "巳(蛇)","午(马)","未(羊)","申(猴)","酉(鸡)","戌(狗)","亥(猪)");
#农历月份
$mmonth=array("闰","正","二","三","四","五","六",
              "七","八","九","十","十一","十二","月");
#农历日
$mday=array("null","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",
            "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
            "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十");
##############################
#赋给初值
#天干地支
$ten=0;
$twelve=0;
#星期
$week=5;
#农历日
$md=0;
#农历月
$mm=0;
#阳历总天数 至1900年12月21日
$total=11;
#阴历总天数
$mtotal=0;
##############################
#获得当日日期
$today=getdate();
#如果没有输入,设为当日日期
if ($year=="" or $month=="" or ($year<1901 or $year>2020)
    or ($month<1 or $month>12)){
     $year=$today[year];
     $month=$today[mon];
   }
##############################
#计算到所求日期阳历的总天数-自1900年12月21日始
#先算年的和
for ($y=1901;$y<$year;$y++){
      $total+=365;
      if ($y%4==0) $total ++;
    }
#再加当年的几个月
switch ($month){
         case 12:
              $total+=30;
         case 11:
              $total+=31;
         case 10:
              $total+=30;
         case 9:
              $total+=31;
         case 8:
              $total+=31;
         case 7:
              $total+=30;
         case 6:
              $total+=31;
         case 5:
              $total+=30;
         case 4:
              $total+=31;
         case 3:
              $total+=28;
         case 2:
              $total+=31;
       }
#如果当年是闰年还要加一天
if ($year%4==0 and $month>2){
     $total++;
    }
#顺便算出当月1日星期几
$week=($total+$week)%7;
##############################
#用农历的天数累加来判断是否超过阳历的天数
$flag1=0;#判断跳出循环的条件
$j=0;
while ($j<=120){
      $i=1;
      while ($i<=13){
            $mtotal+=$everymonth[$j][$i];
            if ($mtotal>=$total){
                 $flag1=1;
                 break;
               }
            $i++;
          }
      if ($flag1==1) break;
      $j++;
    }
##############################
#计算所求月份1号的农历日期
$md=$everymonth[$j][$i]-($mtotal-$total);
#月头空开的天数
$k=$week;
#是否跨越一年
switch ($month){
         case 1:
         case 3:
         case 5:
         case 7:
         case 8:
         case 10:
         case 12:
              $dd=31;
              break;
         case 4:
         case 6:
         case 9:
         case 11:
              $dd=30;
              break;
         case 2:
              if ($year%4==0){
                  $dd=29;
                 }else{
                  $dd=28;
                 }
              break;
       }
#是否跨越一年
$ty=0;
if ((($everymonth[$j][0]<>0 and $i==13) or ($everymonth[$j][0]==0 and $i==12))
       and $mtotal-$total<$dd) $ty=1;
?>


世纪万年历



//打印年月抬头
    echo "

".$year."年".$month."月

\n"; if($ty==0) { echo "

".$mten[$everymonth[$j][14]].$mtwelve[$everymonth[$j][15]]."年

"; } else { echo "

".$mten[$everymonth[$j][14]].$mtwelve[$everymonth[$j][15]]."/".$mten[$everymonth[$j+1][14]].$mtwelve[$everymonth[$j+1][15]]."年

"; } ?>
$day=1; $line=0; while ($day<=$dd){ echo "\n"; for ($s=0;$s<=6;$s++){ if ($k<>0 or $day>$dd){ echo "\n"; $k--; }else{ //设置字符颜色switch ($s){ case 1: case 2: case 3: case 4: case 5: $color="#000000"; break; case 0: $color="#FF0000"; break; case 6: $color="#008000"; break; } #生成中文农历if ($md==1){#1日打印月份if ($everymonth[$j][0]<>0 and $everymonth[$j][0]<$i){ $mm=$i-1; }else{ $mm=$i; } if ($i==$everymonth[$j][0]+1 and $everymonth[$j][0]<>0) $chi=$mmonth[0].$mmonth[$mm];#闰月else$chi=$mmonth[$mm].$mmonth[13]; }else{ $chi=$mday[$md]; } echo "\n"; $day++; $md++; if ($md>$everymonth[$j][$i]){ $md=1; $i++; } if (($i>12 and $everymonth[$j][0]==0) or ($i>13 and $everymonth[$j][0]<>0)){ $i=1; $j++; } } } echo "\n"; $line++; } ?>
星期日 星期一 星期二 星期三 星期四 星期五 星期六
  $color\">$day $chi
php #补足空行 for ($l=1;$l<=(6-$line);$l++){ echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
a
\n"; } #打印上一月,下一月 $ly=$ny=$year; $last=$month-1; if ($last==0){ $last=12; $ly--; } $next=$month+1; if ($next==13){ $next=1; $ny++; } if ($ly>=1901) echo "

$file."?year=".$ly."&month=".$last."\"><<上一个月   \n"; else echo "

"; if ($ny<=2020) echo "$file."?year=".$ny."&month=".$next."\">下一个月>>

\n"; ?> php echo "
$file."\">\n"; ?>

年份:   &nbsp; 月份:月    

// PHPMINE v1.0 
    //来源http://www.phpvault.com 
    //是根据microsoft的挖地雷游戏编写 
    print ""; 
    print ""; 
    print "PHP挖地雷"; 
    print ""; 
    print "
"; print "PHP挖地雷"; if ($submit=="") { $NumMine=4; $RowSize=5; $ColSize=5; $generer=1; } if($generer==1) { srand((double)microtime()*100000000); $time_start=time(); //判断输入的数值是否正确 if(($RowSize<=1) || ($ColSize<=1) || ($NumMine==0)) { print "


行数,列数或地雷数输入错误!!"; exit; } if($NumMine > $RowSize*$ColSize) { print "


地雷数太多!"; exit; } //初始化 for($Row=1;$Row<=$RowSize;$Row++) { for($Col=1;$Col<=$ColSize;$Col++) { $Mine[$Row][$Col]="0"; $Decouv[$Row][$Col]="0"; } } $index=0; while($index<$NumMine) { $Row=rand(1,$RowSize); $Col=rand(1,$ColSize); if($Mine[$Row][$Col]=="0") { $Mine[$Row][$Col]="1"; $index++; } } } else { $perdu=0; $reste=$RowSize*$ColSize; for($Row=1;$Row<=$RowSize;$Row++) { for($Col=1;$Col<=$ColSize;$Col++) { $temp="Mine".($Row*($ColSize+1)+$Col); $Mine[$Row][$Col]=$$temp; $temp="Decouv".($Row*($ColSize+1)+$Col); $Decouv[$Row][$Col]=$$temp; if($Decouv[$Row][$Col]=="1") {$reste=$reste-1;} $temp="submit".($Row*($ColSize+1)+$Col); if($$temp=="ok") { $reste=$reste-1; if($Mine[$Row][$Col]=="0") { $Decouv[$Row][$Col]="1"; } else { $perdu=1; } } } } if($perdu==1) { print "

您输啦!

"; for($i=1;$i<=$RowSize;$i++) { for($j=1;$j<=$ColSize;$j++) { $Decouv[$i][$j]="1"; } } } if(($reste==$NumMine)&&($perdu!=1)) { print "

你赢啦!

"; $time_stop=time(); $time=$time_stop-$time_start; print "

您的分数: $time"; for ($i=1;$i<=$RowSize;$i++) { for($j=1;$j<=$ColSize;$j++) { $Decouv[$i][$j]="1"; } } } } print "

"; print "$time_start>"; print "$NumMine>"; print "$RowSize>"; print "$ColSize>"; print ""; print "

"; for($Row=1; $Row<=$RowSize; $Row++) { print ""; for($Col=1; $Col<=$ColSize; $Col++) { $nb=0; for($i=-1; $i<=1; $i++) { for($j=-1; $j<=1; $j++) { if($Mine[$Row+$i][$Col+$j] == "1") { $nb++; } } } print ""; } print ""; } print "
"; if($Decouv[$Row][$Col]=="1") { if($nb==0) { print " "; } else { if($Mine[$Row][$Col]=="1") { print "*"; } else { print "$nb"; } } } else { print ""; print "$Row*($ColSize+1)+$Col)." value=ok>"; } print "$Row*($ColSize+1)+$Col)." value=".$Mine[$Row][$Col].">"; print "$Row*($ColSize+1)+$Col)." value=".$Decouv[$Row][$Col].">"; print "
"; print "
"; ?>
行数 : &nbsp;
列数 : &nbsp;
地雷数 : &nbsp;

 

转载于:https://www.cnblogs.com/yxhblogs/p/4758806.html

你可能感兴趣的:(PHP实用小程序(七))