PHP
<?php
declare(strict_types=1);
// Example data
$username = "Susan";
$count = 287;
// ---------------------------------------
// LEVEL SYSTEM (clean, scalable)
// ---------------------------------------
$levels = [
12800 => 10,
6400 => 9,
3200 => 8,
1600 => 7,
800 => 6,
400 => 5,
200 => 4,
100 => 3,
50 => 2,
0 => 1
];
// Determine level
$lvl = 1;
foreach ($levels as $xp => $level) {
if ($count >= $xp) {
$lvl = $level;
break;
}
}
// ---------------------------------------
// RENDER STARS (★)
// ---------------------------------------
$stars = str_repeat("★", $lvl);
?>
<!DOCTYPE html>
<html>
<body style="font-family:Arial, sans-serif; font-size:16px;">
<p style="font-size:22px; color:#f4b400;">
<?= $stars ?>
</p>
<p>
<strong><?= htmlspecialchars($username) ?></strong>
is level <strong><?= $lvl ?></strong>
with <strong><?= $count ?></strong> XP
</p>
</body>
</html>
Article discussion
Share your thoughts about this article.
Log in or create an account to comment.
No comments yet. Be the first to join the discussion.