php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78205 echo is not working
Submitted: 2019-06-25 10:06 UTC Modified: 2019-06-25 10:13 UTC
From: manojneed at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1Git-2019-06-25 (Git) OS: window7
Private report: No CVE-ID: None
 [2019-06-25 10:06 UTC] manojneed at gmail dot com
Description:
------------
Hi,
using PHP Version 7.1.12 when i am tring to printing Pattern 

like
     *
    * *
   * * *
  * * * *
 * * * * *


my code
<?php

for($i=1;$i<=5;$i++){
for($k=5;$k>$i;$k--){
echo " ";
//echo " ";
}
for($j=1;$j<=$i;$j++){
echo "*" ;
}
print "<br/>";
}
?>

in the second loop my first echo giving me output like

*
**
***
****
*****
which is not as expected

when i go with second echo code below

for($i=1;$i<=5;$i++){
for($k=5;$k>$i;$k--){
//echo " ";
echo " ";
}
for($j=1;$j<=$i;$j++){
echo "*" ;
}
print "<br/>";
}
?>
i get my desired output like



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

strange both echo syntax is same why first echo not working.please help me 

Test script:
---------------
    *
   **
  ***
 ****
*****


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-25 10:13 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-06-25 10:13 UTC] requinix@php.net
The second is using a non-breaking space. https://en.wikipedia.org/wiki/Non-breaking_space

Replace the
  echo " ";
with
  echo "&nbsp;";
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC