Write a PHP program to find the Fibonacci series

All star pattern programs in PHP

Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following exercise.

PHP program to print Right Triangle

*
* *
* * *
* * * *
* * * * *
<?php
for($i=1;$i<=5;$i++)
{
   for ($j=1;$j<=$i;$j++)
    {
     echo "*";
        if($j< $i)
         {
           echo "&nbsp ";
         }
     }
 echo "<br>";
}
?>

PHP program to print Square Star Pattern

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

<?php
 
for ($i = 1; $i <= 5; $i++)
{
 
    for ($y = 1; $y <= 5; $y++)
    {
        echo '*';
    }
 
    echo "<br>";
 
}

PHP program to print Inverted Right Triangle Star Pattern

* * * * *
* * * *
* * *
* *
*

<?php
 
for ($i = 1; $i <= 5; $i++)
{
 
    for ($j = 1; $j <= 6 - $i; $j++)
    {
        echo '* ';
    }
 
    echo "<br>";
 
}

PHP program to print Inverted Right Triangle

*
* *
* * *
* *
*

<?php
for ($i = 1; $i <= 5; $i++)
{
    for ($j = 1; $j <= ($i > 3 ? 6 - $i : $i); $j++)
    {
        echo '* ';
    }
 
    echo "<br>";
 
}

PHP program to print alphabet pattern ‘A’

 <?php
 for ($i=0; $i<=7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
        if ((($j == 1 or $j == 5) and $i != 0) or (($i == 0 or $i == 3) and ($j > 1 and $j < 5)))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
 
?>

PHP program to print alphabet pattern ‘B’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
      if ($j == 1 or (($i == 0 or $i == 3 or $i == 6) and ($j < 5 and $j > 1)) or ($j == 5 and ($i != 0 and $i != 3 and $i != 6)))
            echo "*";    
        else  
            echo "&nbsp ";  
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘D’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
 
     if ($j == 1 or (($i == 0 or $i == 6) and ($j > 1 and $j < 5)) or ($j == 5 and $i != 0 and $i != 6))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘E

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
 
     if ($j == 1 or (($i == 0 or $i == 6) and ($j > 1 and $j < 6)) or ($i == 3 and $j > 1 and $j < 5))
            echo "*";    
        else  
 
            echo "&nbsp ";     
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘F’

*****
*
*
****
*
*
*

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
      if ($j == 1 or ($i == 0 and $j > 1 and $j < 6) or ($i == 3 and $j > 1 and $j < 5))
            echo "* ";    
        else  
            echo " ";     
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘G’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
    if (($j == 1 and $i != 0 and $i != 6) or (($i == 0 or $i == 6) and $j > 1 and $j < 5) or ($i == 3 and $j > 2 and $j < 6) or ($j == 5 and $i != 0 and $i != 2 and $i != 6))
            echo "*";    
        else  
            echo "&nbsp ";     
 
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘H’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
   if (($j == 1 or $j == 5) or ($i == 3 and $j > 1 and $j < 6))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘I’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
   if ($j == 3 or ($i == 0 and $j > 0 and $j < 6) or ($i == 6 and $j > 0 and $j < 6))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘J’

 <?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if (($j == 4 and $i != 6) or ($i == 0 and $j > 2 and $j < 6) or ($i == 6 and $j == 3) or ($i == 5 and $j == 2))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘K’

<?php
$a = 5;    
$b = 0;  
for ($row=0; $row<=7; $row++)
{
    for ($column=0; $column<=7; $column++)
      {
        if ($column == 1 or (($row == $column + 1) and $column != 0))
            echo "*";   
        else if ($row == $b and $column == $a)
           {  
              echo "*";    
              $b=$b+1;  
              $a=$a-1;
           }
        else
            echo "&nbsp ";   
}    
     echo "<br>";    
}
?>

PHP program to print alphabet pattern ‘L’

*
*
*
*
*
*
*****

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ($j == 1 or ($i == 6 and $j != 0 and $j < 6))
            echo "* ";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘M’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ($j == 1 or $j == 5 or ($i == 2 and ($j == 2 or $j == 4)) or ($i == 3 and $j == 3))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘N’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ($j == 1 or $j == 5 or ($i == $j and $j != 0 and $j != 6))
            echo "*";    
        else  
            echo "&nbsp ";     
 
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘O’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ((($j == 1 or $j == 5) and $i != 0 and $i != 6) or (($i == 0 or $i == 6) and $j > 1 and $j < 5))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘P’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ($j == 1 or (($i == 0 or $i == 3) and $j > 0 and $j < 5) or (($j == 5 or $j == 1) and ($i == 1 or $i == 2)))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘Q’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if (($j == 1 and $i != 0 and $i != 6) or ($i == 0 and $j > 1 and $j < 5) or ($j == 5 and $i != 0 and $i != 5) or ($i == 6 and $j > 1 and $j < 4) or ($j == $i - 1 and $i > 3))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘R’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ($j == 1 or (($i == 0 or $i == 3) and $j > 1 and $j < 5) or ($j == 5 and $i != 0 and $i < 3) or ($j == $i - 1 and $i > 2))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘S’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ((($i == 0 or $i == 3 or $i == 6) and $j > 1 and $j < 5) or ($j == 1 and ($i == 1 or $i == 2 or $i == 6)) or ($j == 5 and ($i == 0 or $i == 4 or $i == 5)))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘T’

<?php
for ($i=0; $i<6; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
  if ($j == 3 or ($i == 0 and $j > 0 and $j < 6))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘U’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
        if ((($j == 1 or $j == 5) and $i != 6) or ($i == 6 and $j > 1 and $j < 5))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘V’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
          if ((($j == 1 or $j == 5) and $i < 5) or ($i == 6 and $j == 3) or ($i == 5 and ($j == 2 or $j == 4)))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
 
?>

PHP program to print alphabet pattern ‘W’

<?php
for ($row=0; $row<7; $row++)
{
  for ($column=0; $column<=7; $column++)
    {
        if ((($column == 1 or $column == 5) and $row < 6) or (($row == 5 or $row == 4) and $column == 3) or ($row == 6 and ($column == 2 or $column == 4)))   
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

PHP program to print alphabet pattern ‘X’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
       if ((($j == 1 or $j == 5) and ($i > 4 or $i < 2)) or $i == $j and $j > 0 and $j < 6 or ($j == 2 and $i == 4) or ($j == 4 and $i == 2))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
 
}
?>

 


PHP program to print alphabet pattern ‘Y’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
        if ((($j == 1 or $j == 5) and $i < 2) or $i == $j and $j > 0 and $j < 4 or ($j == 4 and $i == 2) or (($j == 3) and $i > 3))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘Z’

<?php
for ($row=0; $row<7; $row++)
{
  for ($column=0; $column<=7; $column++)
    {
     if ((($row == 0 or $row == 6) and $column >= 0 and $column <= 6) or $row+$column==6)
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
?>

PHP program to print alphabet pattern ‘C’

<?php
for ($i=0; $i<7; $i++)
{
  for ($j=0; $j<=7; $j++)
    {
     if (($j == 1 and ($i != 0 and $i != 6)) or (($i == 0 or $i == 6) and ($j > 1 and $j < 5)) or ($j == 5 and ($i == 1 or $i == 5)))
            echo "*";    
        else  
            echo "&nbsp ";     
    }        
  echo "<br>";
}
?>

PHP Program to print Diamond Star Pattern

<?php  
    for($i=0;$i<=5;$i++){  
    for($k=5;$k>=$i;$k--){  
    echo "&nbsp";  
    }  
    for($j=1;$j<=$i;$j++){  
        echo "* ";  
    }  
    echo "<br>";  
    }	  
        for($i=4;$i>=1;$i--){  
        for($k=5;$k>=$i;$k--){  
        echo "&nbsp";  
    }  
    for($j=1;$j<=$i;$j++){  
    echo "* ";  
    }  
    echo "<br>";  
}  
?>

PHP Program to print Half Diamond Star Pattern

*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*

<?php  
 
    for($i=1; $i<=5; $i++){   
    for($j=1; $j<=$i; $j++){   
    echo ' * ';   
    }  
        echo '<br>';   
    }  
    for($i=5; $i>=1; $i--){   
    for($j=1; $j<=$i; $j++){  
        echo ' * ';   
    }   
    echo '<br>';   
}   
?>

 

Add a Comment

Your email address will not be published. Required fields are marked *