PHP 垂直字母表使用 FOR 循环
PHP Vertical Alphabet Using FOR Cycle
我正在尝试在 PHP 中编写一个脚本,该脚本将生成一个 table,其中包含垂直字母表。它会简单地回显从 A 到 Z 的字母,当涉及到 Z 时,它会重置并再次从 A 开始。我对此有疑问,因为我只能重复两次,然后所有细胞中都有一些不需要的迹象。我正在使用他们的 ASCII html 代码回显字母,其中 A 符号是 A,Z 符号是 Z.
这是我到目前为止的代码,感谢您的帮助。
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Vertical alphabet</title>
</head>
<body>
<form method="post">
<input type="number" placeholder="COLUMNS" name="cols" />
<input type="number" placeholder="ROWS" name="rows" />
<input type="submit" value="Create table" /><br><br>
</form>
<?php
if(isset($_POST['rows']) && isset($_POST['cols'])) {
$col = $_POST['cols'];
$row = $_POST['rows'];
echo ("<table rules='all'>");
for($i = 1; $i<$row+1; $i++) {
echo ("<tr>");
for($c = 0; $c<$col; $c++) {
$letter_id = 65;
$number = ($i + ($c*$row)-1);
$letter = $number + $letter_id;
if($letter > 90) {
$number = $number - 26;
$letter = $letter - 26;
echo ("<td>". "&#" . $letter. "</td>");
} else {
echo ("<td>". "&#" . $letter. "</td>");
}
}
echo ("</tr>");
}
echo ("</table>");
}
?>
</body>
</html>
因为 $number 总是长大的。
第一个A-Z,$number在0到25之间,你去else就可以了
第二个 A-Z,$number 在 26 到 51 之间,你在 if 情况下,你去掉 26 你的打印就可以了。
下一个 $number 是 52,和之前一样,你在 if 情况下尝试打印字母表中的第 27 个字母 ^^
不确定您要对 $number
变量做什么,但这就是这里的问题
$number = 0;
echo ("<table rules='all'>");
for($i = 1; $i<=$row; $i++) {
echo ("<tr>");
for($c = 0; $c<$col; $c++) {
$letter_id = 65;
$number = $i + ($c*$row);
$letter = $number + $letter_id;
while($letter > 90) {
$letter = $letter - 26;
}
echo ("<td>". "&#" . $letter. "</td>");
}
echo ("</tr>");
}
echo ("</table>");
更新:
现在垂直,试试这个...
我正在尝试在 PHP 中编写一个脚本,该脚本将生成一个 table,其中包含垂直字母表。它会简单地回显从 A 到 Z 的字母,当涉及到 Z 时,它会重置并再次从 A 开始。我对此有疑问,因为我只能重复两次,然后所有细胞中都有一些不需要的迹象。我正在使用他们的 ASCII html 代码回显字母,其中 A 符号是 A,Z 符号是 Z.
这是我到目前为止的代码,感谢您的帮助。
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Vertical alphabet</title>
</head>
<body>
<form method="post">
<input type="number" placeholder="COLUMNS" name="cols" />
<input type="number" placeholder="ROWS" name="rows" />
<input type="submit" value="Create table" /><br><br>
</form>
<?php
if(isset($_POST['rows']) && isset($_POST['cols'])) {
$col = $_POST['cols'];
$row = $_POST['rows'];
echo ("<table rules='all'>");
for($i = 1; $i<$row+1; $i++) {
echo ("<tr>");
for($c = 0; $c<$col; $c++) {
$letter_id = 65;
$number = ($i + ($c*$row)-1);
$letter = $number + $letter_id;
if($letter > 90) {
$number = $number - 26;
$letter = $letter - 26;
echo ("<td>". "&#" . $letter. "</td>");
} else {
echo ("<td>". "&#" . $letter. "</td>");
}
}
echo ("</tr>");
}
echo ("</table>");
}
?>
</body>
</html>
因为 $number 总是长大的。
第一个A-Z,$number在0到25之间,你去else就可以了
第二个 A-Z,$number 在 26 到 51 之间,你在 if 情况下,你去掉 26 你的打印就可以了。
下一个 $number 是 52,和之前一样,你在 if 情况下尝试打印字母表中的第 27 个字母 ^^
不确定您要对 $number
变量做什么,但这就是这里的问题
$number = 0;
echo ("<table rules='all'>");
for($i = 1; $i<=$row; $i++) {
echo ("<tr>");
for($c = 0; $c<$col; $c++) {
$letter_id = 65;
$number = $i + ($c*$row);
$letter = $number + $letter_id;
while($letter > 90) {
$letter = $letter - 26;
}
echo ("<td>". "&#" . $letter. "</td>");
}
echo ("</tr>");
}
echo ("</table>");
更新:
现在垂直,试试这个...