Help centering text

Status
This thread has been locked.

Prince Royce

Feedback score
0
Posts
26
Reactions
5
Resources
0
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.
 
Last edited:
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Mooselk

Motocross enthusiast
Premium
Feedback score
9
Posts
298
Reactions
213
Resources
0
str_repeat('&nbsp;', 5);

That doesn't work? I'm not the great with php but maybe something like this

echo "<p>&nbsp;&nbsp;&nbsp; +++ Header +++";
 
Last edited:
Status
This thread has been locked.
Top