要求
使用php打印 ”
*
“ 为金字塔形状。
注意:必须添加字体(任意字体,自行调式),否则金字塔会变形。
效果图
index.php代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>打印金字塔</title>
<style type="text/css">
body {
background-color: #dedede;
font-family: "楷体";
}
.main {
border: 7px dotted #00bcff;
width: 538px;
height: 333px;
margin: 222px auto;
font-size: 28px;
}
h1 {
text-align: center;
}
.a1 {
margin: 0 auto;
width: 120px;
}
#ajax {
color: red;
}
</style>
</head>
<body>
<div class="main">
<h1>打印金字塔</h1>
<div class="a1">
<?php
$j = 1;
while ($j <= 5) {
$space = 1;
while ($space <= 5 - $j) {
echo " ";
$space = $space + 1;
}
$i = 1;
while ($i <= 2 * $j - 1) {
echo "*";
$i = $i + 1;
}
echo "<br/>";
$j = $j + 1;
}
?>
</div>
</div>
</body>
</html>