-2

I am trying to print the letter 'A' using star pattern but somewhere I am getting wrong. The code is as follow-

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

?>

The letter A does not appear in proper format.

Umar
  • 990
  • 1
  • 8
  • 19
  • 2
    Are you viewing it in a browser? It is correct to me. Replace the space with ` ` if viewing in a browser. Multiple single spaces are joined in browsers. Your current code, https://eval.in/841189. – chris85 Aug 03 '17 at 14:49
  • 2
    ... or output it in a `pre` element. There is nothing wrong with the code per se; but your knowledge of HTML basics such as how whitespace is handled seems to need improving ... – CBroe Aug 03 '17 at 14:50
  • the other option is to echo your letter inside a `
    ` tag to keep all the spaces and replace `
    ` with `\n`
    – ᴄʀᴏᴢᴇᴛ Aug 03 '17 at 14:50
  • Thank you all! your comments helped me a lot. – Umar Aug 03 '17 at 14:57

2 Answers2

1

You shouldn't use spaces. CHoose another character or use &nbsp;, which is an unbreakable space.

Web browsers remove consecutive spaces so that there is only one space between two non-spaces characters. That's why your display looks broken.

Unbreakable spaces will be printed no matter what.

Sarkouille
  • 1,275
  • 9
  • 16
0

Just add in your else block echo "&nbsp;&nbsp;";

Omi
  • 3,954
  • 5
  • 21
  • 41