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 excercise.


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999



PHP program to print Right Triangle

*  
* *  
* * *  
* * * *  
* * * * *   
  1. <?php
  2. for($i=1;$i<=5;$i++)
  3. {
  4. for ($j=1;$j<=$i;$j++)
  5. {
  6. echo "*";
  7. if($j< $i)
  8. {
  9. echo "&nbsp ";
  10. }
  11. }
  12. echo "<br>";
  13. }
  14. ?>

PHP program to print Square Star Pattern

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
  1. <?php
  2.  
  3. for ($i = 1; $i <= 5; $i++)
  4. {
  5.  
  6. for ($y = 1; $y <= 5; $y++)
  7. {
  8. echo '*';
  9. }
  10.  
  11. echo "<br>";
  12.  
  13. }

PHP program to print Inverted Right Triangle Star Pattern

* * * * *
* * * *
* * *
* *
*
  1. <?php
  2.  
  3. for ($i = 1; $i <= 5; $i++)
  4. {
  5.  
  6. for ($j = 1; $j <= 6 - $i; $j++)
  7. {
  8. echo '* ';
  9. }
  10.  
  11. echo "<br>";
  12.  
  13. }

PHP program to print Inverted Right Triangl

*
* *
* * *
* *
* 
  1.  
  2. <?php
  3. for ($i = 1; $i <= 5; $i++)
  4. {
  5. for ($j = 1; $j <= ($i > 3 ? 6 - $i : $i); $j++)
  6. {
  7. echo '* ';
  8. }
  9.  
  10. echo "<br>";
  11.  
  12. }
  13.  

PHP program to print alphabet pattern 'A'

  ***
 *   *
 *   *
 *****
 *   *
 *   *
 *   *
 *   *
  1.  
  2. <?php
  3. for ($i=0; $i<=7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ((($j == 1 or $j == 5) and $i != 0) or (($i == 0 or $i == 3) and ($j > 1 and $j < 5)))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13. }
  14.  
  15. ?>
  16.  

PHP program to print alphabet pattern 'B'

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


  1. <?php
  2. for ($i=0; $i<7; $i++)
  3. {
  4. for ($j=0; $j<=7; $j++)
  5. {
  6. 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)))
  7. echo "*";
  8. else
  9. echo "&nbsp ";
  10. }
  11. echo "<br>";
  12. }
  13. ?>
  14.  

     


PHP program to print alphabet pattern 'D'

 ****
 *   *
 *   *
 *   *
 *   *
 *   *
 ****
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7.  
  8. if ($j == 1 or (($i == 0 or $i == 6) and ($j > 1 and $j < 5)) or ($j == 5 and $i != 0 and $i != 6))
  9. echo "*";
  10. else
  11. echo "&nbsp ";
  12. }
  13. echo "<br>";
  14.  
  15. }
  16. ?>
  17.  
  18.  

PHP program to print alphabet pattern 'E

 *****
 *
 *
 ****
 *
 *
 *****
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7.  
  8. if ($j == 1 or (($i == 0 or $i == 6) and ($j > 1 and $j < 6)) or ($i == 3 and $j > 1 and $j < 5))
  9. echo "*";
  10. else
  11.  
  12. echo "&nbsp ";
  13. }
  14. echo "<br>";
  15. }
  16. ?>

PHP program to print alphabet pattern 'F'

 *****
 *
 *
 ****
 *
 *
 *
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ($j == 1 or ($i == 0 and $j > 1 and $j < 6) or ($i == 3 and $j > 1 and $j < 5))
  8. echo "* ";
  9. else
  10. echo " ";
  11. }
  12. echo "<br>";
  13. }
  14. ?>
  15.  

PHP program to print alphabet pattern 'G'

  ***
 *   *
 *
 * ***
 *   *
 *   *
  ***
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. 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))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11.  
  12. }
  13. echo "<br>";
  14. }
  15. ?>

PHP program to print alphabet pattern 'H'

 *   *
 *   *
 *   *
 *****
 *   *
 *   *
 *   *
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if (($j == 1 or $j == 5) or ($i == 3 and $j > 1 and $j < 6))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'I'

 *****
   *
   *
   *
   *
   *
 *****
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ($j == 3 or ($i == 0 and $j > 0 and $j < 6) or ($i == 6 and $j > 0 and $j < 6))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'J'

   ***
    *
    *
    *
    *
  * *
   *

  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. 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))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'K'

 *   *
 *  *
 * *
 **
 * *
 *  *
 *   *
 *    *
  1. <?php
  2. $a = 5;
  3. $b = 0;
  4. for ($row=0; $row<=7; $row++)
  5. {
  6. for ($column=0; $column<=7; $column++)
  7. {
  8. if ($column == 1 or (($row == $column + 1) and $column != 0))
  9. echo "*";
  10. else if ($row == $b and $column == $a)
  11. {
  12. echo "*";
  13. $b=$b+1;
  14. $a=$a-1;
  15. }
  16. else
  17. echo "&nbsp ";
  18. }
  19. echo "<br>";
  20. }
  21. ?>

Star pattern 15

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

PHP program to print alphabet pattern 'M'

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

  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ($j == 1 or $j == 5 or ($i == 2 and ($j == 2 or $j == 4)) or ($i == 3 and $j == 3))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>


PHP program to print alphabet pattern 'N'

 *   *
 *   *
 **  *
 * * *
 *  **
 *   *
 *   *
  1. <?php
  2. for ($i=0; $i<7; $i++)
  3. {
  4. for ($j=0; $j<=7; $j++)
  5. {
  6. if ($j == 1 or $j == 5 or ($i == $j and $j != 0 and $j != 6))
  7. echo "*";
  8. else
  9. echo "&nbsp ";
  10.  
  11. }
  12. echo "<br>";
  13. }
  14. ?>

PHP program to print alphabet pattern 'O'

  ***
 *   *
 *   *
 *   *
 *   *
 *   *
  ***
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ((($j == 1 or $j == 5) and $i != 0 and $i != 6) or (($i == 0 or $i == 6) and $j > 1 and $j < 5))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'P'

 ****
 *   *
 *   *
 ****
 *
 *
 *
  1. <?php
  2. for ($i=0; $i<7; $i++)
  3. {
  4. for ($j=0; $j<=7; $j++)
  5. {
  6. 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)))
  7. echo "*";
  8. else
  9. echo "&nbsp ";
  10. }
  11. echo "<br>";
  12.  
  13. }
  14. ?>

PHP program to print alphabet pattern 'Q'

  ***
 *   *
 *   *
 *   *
 * * *
 *  *
  ** *
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. 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))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13. }
  14. ?>

PHP program to print alphabet pattern 'R'

 ****
 *   *
 *   *
 ****
 * *
 *  *
 *   *
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. 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))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'S'

  ****
 *
 *
  ***
     *
     *
 ****
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. 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)))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'T'

 *****
   *
   *
   *
   *
   *                   
  1.  
  2. <?php
  3. for ($i=0; $i<6; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ($j == 3 or ($i == 0 and $j > 0 and $j < 6))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'U'

 *   *
 *   *
 *   *
 *   *
 *   *
 *   *
  ***
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ((($j == 1 or $j == 5) and $i != 6) or ($i == 6 and $j > 1 and $j < 5))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13. }
  14. ?>

PHP program to print alphabet pattern 'V'

 *   *
 *   *
 *   *
 *   *
 *   *
  * *
   *
  1.  
  2. <?php
  3. for ($i=0; $i<7; $i++)
  4. {
  5. for ($j=0; $j<=7; $j++)
  6. {
  7. if ((($j == 1 or $j == 5) and $i < 5) or ($i == 6 and $j == 3) or ($i == 5 and ($j == 2 or $j == 4)))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13. }
  14.  
  15. ?>

PHP program to print alphabet pattern 'W'

 *   *
 *   *
 *   *
 *   *
 * * *
 * * *
  * *
  1.  
  2. <?php
  3. for ($row=0; $row<7; $row++)
  4. {
  5. for ($column=0; $column<=7; $column++)
  6. {
  7. 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)))
  8. echo "*";
  9. else
  10. echo "&nbsp ";
  11. }
  12. echo "<br>";
  13.  
  14. }
  15. ?>

PHP program to print alphabet pattern 'X'

 *   *
 *   *
  * *
   *
  * *
 *   *
 *   *
  1. <?php
  2. for ($i=0; $i<7; $i++)
  3. {
  4. for ($j=0; $j<=7; $j++)
  5. {
  6. 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))
  7. echo "*";
  8. else
  9. echo "&nbsp ";
  10. }
  11. echo "<br>";
  12.  
  13. }
  14. ?>

Star pattern 28

 *   *
 *   *
  * *
   *
   *
   *
   *
  1. <?php
  2. for ($i=0; $i<7; $i++)
  3. {
  4. for ($j=0; $j<=7; $j++)
  5. {
  6. 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))
  7. echo "*";
  8. else
  9. echo "&nbsp ";
  10. }
  11. echo "<br>";
  12. }
  13. ?>

PHP program to print alphabet pattern 'Z'

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

PHP program to print alphabet pattern 'C'

  ***                                                       
 *   *                                                      
 *                                                          
 *                                                          
 *                                                          
 *   *                                                      
  *** 
  1. <?php
  2. for ($i=0; $i<7; $i++)
  3. {
  4. for ($j=0; $j<=7; $j++)
  5. {
  6. 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)))
  7. echo "*";
  8. else
  9. echo "&nbsp ";
  10. }
  11. echo "<br>";
  12. }
  13. ?>

PHP Program to print Diamond Star Pattern

     * 
    * * 
   * * * 
  * * * * 
 * * * * * 
  * * * * 
   * * * 
    * * 
     * 
  1. <?php
  2. for($i=0;$i<=5;$i++){
  3. for($k=5;$k>=$i;$k--){
  4. echo "&nbsp";
  5. }
  6. for($j=1;$j<=$i;$j++){
  7. echo "* ";
  8. }
  9. echo "<br>";
  10. }
  11. for($i=4;$i>=1;$i--){
  12. for($k=5;$k>=$i;$k--){
  13. echo "&nbsp";
  14. }
  15. for($j=1;$j<=$i;$j++){
  16. echo "* ";
  17. }
  18. echo "<br>";
  19. }
  20. ?>

PHP Program to print Half Diamond Star Pattern

* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * 
* * * * 
* * * 
* * 
* 
  1. <?php
  2.  
  3. for($i=1; $i<=5; $i++){
  4. for($j=1; $j<=$i; $j++){
  5. echo ' * ';
  6. }
  7. echo '<br>';
  8. }
  9. for($i=5; $i>=1; $i--){
  10. for($j=1; $j<=$i; $j++){
  11. echo ' * ';
  12. }
  13. echo '<br>';
  14. }
  15. ?>





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.