I do not know whether it is a character set problem or an algorithm problem.

Source: Internet
Author: User
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.

;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.