Write a script that prompts the user to enter the size of the side of a square and then displays a hollow square of that size made of asterisks. Your script should work for squares of all side lengths between 1 and 20.

For making Hollow Square of Asterisks, I need to use 3 times for loop. It is easy ; check this script.
You should try it.
User will enter a value and will get exact numbers of Asterisks Hollow Square:


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
 $less = ($inputs[0]-2);  
 for ($fl=1; $fl<=$inputs[0]; $fl++)  
   {  
     echo "*";  
     if ($fl==$inputs[0])  
       {  
         echo "<br />";  
       }  
   }  
 for ($hstr=1; $hstr<=$less; $hstr++)  
   {  
     echo "*" . str_repeat("&nbsp;", $less) . "* <br />";  
   }  
 for ($ll=1; $ll<=$inputs[0]; $ll++)  
   {  
     echo "*";  
   }  
 ?>  

Post a Comment

Give your reviews about this blog. Leave your comments. What do you think about this post?

Comments Guidelines:

1) I love to read comments, but please avoid spam.

2) Like this blog, share your insights, and spread the word.

3) You can use basic HTML/xHTML tags.

4) All comments are DoFollow—please use the section professionally.

5) Kindly mention your name or brand below your comment.

6) Constructive suggestions for improvement are always welcome.


Thanks for visiting Samee Articles.

========================================

Best Regards,

Samee U. Feroz

 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger