I would like to create something like this in PHP (note the spaces and the centering of the text)
------- +++ Head Money Top +++
--- 1) Player 1: $ 300,000,000
--- 2) Player 2: $ 40,000
--- 3) Player 3: $ 1,000
--- are spaces due to mc market formatter removes double spaces
If the number is increased, ie the player's money, additional spaces would have to be added at the beginning of the line to maintain the centering, the same with the others, with the longest line (that is, with the most money) being the reference in terms of spaces for the other lines, as can be seen in the result of the previous example.
This is my code:
$ text = "--- Header ---". "\ n";
$ ranking = 1;
foreach ($ moneytop as $ player => $ money) {
$ text. = $ ranking. ")". $ player. ": $". $ money. "\ n";
$ ranking ++;
}
Which results in
--- Header ---
1) Player 1: $ 300,000
2) Player 2: $ 40,000
3) Player 3: $ 1,000
I have made multiple attempts with str_repeat (), for () for each letter with $ i = 0; $ i <strlen ($ text) $ i ++) ...
Note: WITHOUT HTML, because my application runs in the console and the HTML characters are not translated
Thank you for your answers.
------- +++ Head Money Top +++
--- 1) Player 1: $ 300,000,000
--- 2) Player 2: $ 40,000
--- 3) Player 3: $ 1,000
--- are spaces due to mc market formatter removes double spaces
If the number is increased, ie the player's money, additional spaces would have to be added at the beginning of the line to maintain the centering, the same with the others, with the longest line (that is, with the most money) being the reference in terms of spaces for the other lines, as can be seen in the result of the previous example.
This is my code:
$ text = "--- Header ---". "\ n";
$ ranking = 1;
foreach ($ moneytop as $ player => $ money) {
$ text. = $ ranking. ")". $ player. ": $". $ money. "\ n";
$ ranking ++;
}
Which results in
--- Header ---
1) Player 1: $ 300,000
2) Player 2: $ 40,000
3) Player 3: $ 1,000
I have made multiple attempts with str_repeat (), for () for each letter with $ i = 0; $ i <strlen ($ text) $ i ++) ...
Note: WITHOUT HTML, because my application runs in the console and the HTML characters are not translated
Thank you for your answers.
Last edited:
