如何让这个PHP代码输出HTML?

时间:2009-03-21 20:02:00

标签: php

如何输入HTML代码输入HTML以输入玩家编号并生成锦标赛?

<?php
class RoundRobin
{
 var $MaxTeams;
 var $MaxCombinations;
 var $tourn;
 var $mList;
 var $cList;
 var $cUsed;
 function RoundRobin($max)
 {
  $this->MaxTeams=$max;
  $this->MaxCombinations=($this->MaxTeams/2)*($this->MaxTeams-1);
 }
 function ShowSchedule($players,$totalChecks)
 {
   echo $players.' players'."\n";
   for ($r=1; $r <= $players/2; $r++) echo 'Game'.$r;
   echo "\n";
   echo"        +-";
   for ($r=1; $r <= ($players/2)*6-2; $r++) echo '-';
   echo "\n";
   $index = 1;
   for ($r=1; $r <= $players-1; $r++)
   {
     echo 'Week '.$r. '|';
     for ($m=1; $m <= $players/2; $m++)
     {
       echo $this->tourn[$index]['one'].'&amp;'. $this->tourn[$index]['two'];
       $index++;
     }
     echo "\n";
   }
   echo "\n".$totalChecks,' combinations tried'. "\n\n";
 }
 function array_copy(&$dest,$source)
 {
  if(count($source)>count($dest)) {echo 'fatal'; exit;}
  //for($a=0;$a<count($source);$a++)
  $dest['one']=$source['one'];
  $dest['two']=$source['two'];
 }
 function ClearArrays()
 {
   for ($i=0; $i <= $this->MaxCombinations; $i++)
   {
    $this->tourn[$i]['one']=0;
    $this->tourn[$i]['two']=0;
    $this->cList[$i]['one']=0;
    $this->cList[$i]['two']=0;
    $this->cUsed[$i]=0;
    if($i<=$this->MaxTeams/2)$this->mList[$i] = 0;
   }
 }
 function Scheldule($players)
 {
  while ($players <= $this->MaxTeams)
  {
 $combinations = $players/2 * ($players-1);
    $totalChecks = 0;
 $this->ClearArrays();
    /* set up list of all combinations */
     $m=1;
     for ($a=1; $a<$players; $a++)
      for ($b=$a+1; $b<=$players; $b++)
      {
       $this->cList[$m]['one'] = $a;
       $this->cList[$m]['two'] = $b;
       $m++;
      }
    $roundCount=1;
    $index=1;
    while ($roundCount <= $players-1)
     {
       $matchCount = 1;
       $round_set = 0;
       for ($i=0; $i<=$this->MaxTeams/2; $i++) $this->mList[$i] = 0;
       $startC = $roundCount;
         while ($matchCount <= $players/2)
         {
            $c = $combinations + 1;
            while ($c > $combinations)
            {
              $c = $startC;
              /* find an unused pair that would be legitimate */
              while (
                 ($c <= $combinations)
                 &&
                      ( //
                      ($round_set & (1 << $this->cList[$c]['one'])) ||
                       ($round_set & (1 << $this->cList[$c]['two'])) ||
                       (!empty($this->cUsed[$c]))
                      )
                    )   $c++;
                if ($c > $combinations)
                 {
                  do {
                    $this->mList[$matchCount] = 0;
                    $matchCount--;
                    $index--;
                    $round_set &= ~(1 << $this->cList[$this->mList[$matchCount]]['one']);
                    $round_set &= ~(1 << $this->cList[$this->mList[$matchCount]]['two']);
                    $this->cUsed[$this->mList[$matchCount]] = false;
                    $this->tourn[$index]['one'] = 0;
                    $this->tourn[$index]['two'] = 0;
                   }
                   while ($this->cList[$this->mList[$matchCount]]['one'] != $this->cList[$this->mList[$matchCount]+1]['one']);
                  $startC = $this->mList[$matchCount]+1;
                }
            }
            $this->array_copy(&$this->tourn[$index],$this->cList[$c]);
            $totalChecks++;
            if (($totalChecks % 1000) == 0) printf("%d\033A\n", $totalChecks );
            $this->cUsed[$c] = true;
            $this->mList[$matchCount] = $c;
            $startC = 1;
            $round_set |= (1 <<  $this->cList[$c]['one']);
            $round_set |= (1 <<  $this->cList[$c]['two']);
            $index++;
            $matchCount++;
         }
      $roundCount++;
     }
   /* yahoo!, scheduled all the rounds */
    printf("          " );
    $this->ShowSchedule($players,$totalChecks);
    /* try and make a schedule using two more teams */
   $players += 2;
   }
     }
}
?>

1 个答案:

答案 0 :(得分:2)

这是一个PHP类。阅读the manual可能会对您有所帮助。

的某些内容可能会工作:

$rr = new RoundRobin( 5 );

$rr->Scheldule( $_POST['PlayerCount'] );

但是,如果它确实存在,我就不会费心解密代码。

此外,如果您尚未学习HTML表单,请阅读w3schools等教程。