简体   繁体   English

PHP字母表格-A到Z,Z到A

[英]PHP Alphabet table - A to Z, Z to A

I'm trying to do a script in PHP which will generate a table with vertical alphabet in it. 我正在尝试用PHP编写脚本,该脚本将生成一个带有垂直字母的表。 It will simply echo letters from A to Z and then from Z back to A, when it comes to A it will do again from A to Z and from Z to A. 它会简单地将字母从A传到Z,然后从Z回传到A,当涉及到A时,它将再次从A传到Z,再从Z传到A。

My code until now is only from A to Z and then again from A to Z. 到目前为止,我的代码仅是从A到Z,然后是从A到Z。

<!DOCTYPE html>
<html>

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>Vertikální abeceda</title>
</head>

<body>
    <form method="post">
        <input type="number" placeholder="SLOUPCE" name="sloupce" />
        <input type="number" placeholder="ŘÁDKY" name="radky" />
        <input type="submit" value="Vytvořit tabulku" /><br><br>
    </form>

        <?php
            if(isset($_POST['radky']) && isset($_POST['sloupce'])) {
                $col = $_POST['sloupce'];
                $row = $_POST['radky'];
                $cislo = 0;

                echo ("<table rules='all'>");

                for($i = 1; $i<=$row; $i++) {
                    echo ("<tr>");
                    for($c = 0; $c<$col; $c++) {
                        $pismeno_id = 64;
                        $cislo = $i + ($c*$row);
                        $pismeno = $cislo + $pismeno_id;
                        while($pismeno > 90) {
                            $pismeno = $pismeno - 26;
                        }
                        echo ("<td>". "&#" . $pismeno . "</td>");
                    }
                    echo ("</tr>");
                }
                echo ("</table>");
            }
        ?>
</body>
</html>

Here we go: To add the backwards alphabet to the cicle I changed the maximum number of $letter to 115. Thats 65(value of A) + 26(full alphabet) + 24 (X - B). 现在我们开始:为了将后退字母添加到cicle中,我将$ letter的最大数量更改为115。即65(A的值)+ 26(全字母)+ 24(X-B)。

To accomplish the backwards Alphabet, I added variable $realletter, which remains the same as $letter up to 90. From 91 to 115, it counts backwards, by substracting the amount higher than 90 from 90. That would be 90 - ($letter - 90), ie. 为了完成向后的字母,我添加了变量$ realletter,该变量与$ letter相同,直到90。从91到115,通过从90减去高于90的量来进行反向计数。这将是90-($ letter -90),即 for 94 -> 90 - (94 - 90) = 90 - 4 = 86. 对于94-> 90-(94-90)= 90-4 = 86。

<?php
$row = 26;
$col = 26;
echo ("<table rules='all'>");

for($i = 0; $i<=$row; $i++) {
 echo ("<tr>");
 for($c = 0; $c<$col; $c++) {
      $letter_id = 65;
      $number = $i + ($c*$row);
      $letter = $number + $letter_id;
      while($letter > 115) {
            $letter = $letter - 50;
      }
      if($letter > 90){
        $realletter = 90 - ($letter-90); 
      }else{
        $realletter = $letter;
      }
      echo ("<td>". "&#" . $realletter. "</td>");
 }
 echo ("</tr>");
}

echo ("</table>");
?>

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM