2016-03-31 13 views
-1

文字をバイナリに変換し、1と0に対応するテーブルセルを白黒にするコードを作成しました。あなたはそれが8×8テーブルだ見ることができるように特定の行数に達した後に新しいテーブルを作成する

out

$str_splt = str_split($text); 
    echo "<table>"; 
    for ($a=0;$a < count($str_splt);$a++) { 
     $bits = array(128,64,32,16,8,4,2,1); 
     $store = array(0,0,0,0,0,0,0,0); 
     $inp = ord($str_splt[$a]); 
     for ($x=0;$x < count($bits);$x++) { 
      if ($bits[$x] <= $inp) { 
       $inp = $inp - $bits[$x]; 
       $store[$x] = 1; 
      } else { 
       $store[$x] = 0; 
      } 
     }; 
     $store_rvs = array_reverse($store); 
     echo "<tr>"; 
     for ($b=0;$b < count($store_rvs);$b++) { 
      if ($store_rvs[$b] == '1') { 
       echo "<td id=\"blk\"></td>"; 
      } 
      else { 
       echo "<td></td>"; 
      } 
     } 
     echo "</tr>"; 
    } 
    echo "</table>"; 

その出力は、この($text = "ABCDEFGH")のようになります。これは私のコードです。私はこのような、そのテーブルの側にバイトの次のセットを追加したい:

enter image description here

各8×8テーブルがグループです。

enter image description here

私はこのようなテーブルを表示したいが、私は解決策を見つけることができません。上記の二つの画像は、グループ1とグループ2です。

答えて

1

このようにしました。あなたはあなたの罰金があれば私のCSSを無視してください。各idは一度しか定義されていないので、idタグをclassに置き換えました。

echo "<html><head>"; 
echo "<style type='text/css'>"; 
echo " table, td { padding:0px; margin:0px; }"; 
echo " td.cell { width:15px; height:15px; }"; 
echo " td.blk { background-color:black; }"; 
echo " td.wht { background-color:yellow; }"; 
echo "</style>"; 
echo "</head><body>"; 

$text = "ABCDEFGH"; 
$text.= "ABCDEFGH"; 

echo "<table><tr><td><table>"; 
for($a=0; $a<strlen($text); $a++) { 
    $chr = substr($text,$a,1); 
    $bits = array(128,64,32,16,8,4,2,1); 
    $store = array(0,0,0,0,0,0,0,0); 
    $inp = ord($chr); 
    for($x=0; $x<count($bits); $x++) { 
     if($bits[$x] <= $inp) { 
      $inp = $inp - $bits[$x]; 
      $store[$x] = 1; 
     } else { 
      $store[$x] = 0; 
     } 
    } 
    $store_rvs = array_reverse($store); 
    if($a % 8 === 0) { 
     echo "</table></td><td><table>"; 
    } 
    echo "<tr>"; 
    for($b=0; $b<count($store_rvs); $b++) { 
     if($store_rvs[$b] == '1') { 
      echo "<td class='cell blk'></td>"; 
     } else { 
      echo "<td class='cell wht'></td>"; 
     } 
    } 
    echo "</tr>"; 
} 
echo "</table></td></tr></table>"; 
関連する問題