I do not know whether it is a character set problem or an algorithm problem.
for($r=1;$r<=$rows;$r++){ for($n=$rows;$n>$r;$n--){echo " ";} for($m=0;$m<$r ;$m++){echo "*";}echo "
";}
To achieve
But now it becomes
Is it my algorithm problem? I open in IE browser, the default GB2312 character set is displayed correctly, UTF-8 is displayed is wrong.
Is this the case only when the character set problem occurs? how can this problem be solved? Thank you !~
Reply to discussion (solution)
Of course not an algorithm problem!
Originally, this type of question was tested in text mode. you need to put it in html.
$ Rows = 12; echo'';for($r=1;$r<=$rows;$r++){ for($n=$rows;$n>$r;$n--){ echo " "; } for($m=0;$m<$r ;$m++){ echo "*"; } echo PHP_EOL;}
In this way, no deformation will occur. Of course not an algorithm problem!
Originally, this type of question was tested in text mode. if you put it in html, of course, there are some problems with PHP code? 1234567891011 $ rows = 12; echo'
'; For ($ r = 1; $ r <= $ rows; $ r ++) {for ($ n = $ rows; $ n> $ r; $ n --) {echo "" ;}for ($ m = 0; $ m <$ r; $ m ++ ){......
Sure enough! So what does it mean to put it in HTML directly? what is the problem that will lead to deformation? is it because the linefeed and space break occupy different characters in HTML? Set the right alignment of the text in css.
;