Using PHP to generate a Christmas Tree
written by: admin
Date Written: 5/15/12
Last Updated: 5/28/12
Not much point to this script. It uses php to create a Christmas tree.
It was an interesting enough exercise that I decided not to discard it.
demo
<html>
<body><pre>
<?php
$height=25;
$d=1;
$b=($height-1)*2+1;
$f=$b;
$e=floor($b/2);
$a=str_pad('',$b);
while($b>=1){
if ($b==($height-1)*2+1){
$a=substr_replace($a,'*',$e,1);
echo"$a<br>";
$a=substr_replace($a,' ',$e,1);
}
else {
$e=floor($b/2);
$a=substr_replace($a,'*',$e,1);
$a=substr_replace($a,'*',$f-$e-1,1);
echo"$a<br>";
$a=str_pad('',$f);}
$b-=2;
}
?></pre>
</body>
</html>
TAGS: php