Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

white space on echo " ";

Do not want to correct the code I want why echo " "; is not printed in my pyramid shape of *?

$x = 7;
for($i=1;$i<=$x;$i++){
    for($j=1; $j<=$x-$i; ++$j) {
        echo " ";
    }
    for($k=1; $k<=$i; ++$k) {
        echo "* ";
    }
    echo "<br>";
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can enclose your code in <pre> tags to display multiple spaces in the browser. We recommend using "\n" instead of <br>.

echo '<pre>'; 
$x = 7;
for($i=1;$i<=$x;$i++){
    for($j=1; $j<=$x-$i; ++$j) {
        echo " ";
    }
    for($k=1; $k<=$i; ++$k) {
        echo "* ";
    }
    echo "\r\n";
}
echo '</pre>';

Alternatively, a special header can also be set with PHP.

header('Content-Type: text/plain');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading