Skip to content
Torna al Blog
PHP code snippet displaying Minecraft server MOTD with colored text formatting applied

Format Your Minecraft Server Text with PHP

ice
ice
@ice
49 visualizzazioni
TL;DR:PHP-Minecraft provides clean PHP classes for handling Minecraft server text formatting, color codes, JSON components, and votifier voting. Essential for PHP-based server tools, status panels, and admin plugins.
🐙 Open-source Minecraft project

Spirit55555/PHP-Minecraft

Useful PHP classes for Minecraft

⭐ 68 stars💻 PHP📜 GPL-3.0
View on GitHub ↗

Building a Minecraft server in PHP? You'll quickly run into the same problem every admin faces: how do you display formatted, colorful server messages without wrestling with Minecraft's text encoding. PHP-Minecraft solves this by wrapping Minecraft's color code and text formatting systems in clean PHP classes.

Why Your Minecraft Server Needs This

Minecraft uses a non-standard system for formatting text. If you're building server software, plugins, or management tools in PHP, you're handling text that uses either legacy color codes (those §4 symbols that look like nothing) or JSON components. Trying to convert between these formats or apply colors manually is tedious and error-prone.

Here's the thing: server admins want beautiful MOTDs. Players expect colorful server messages. Your PHP code shouldn't make you choose between "easy" and "correct."

PHP-Minecraft handles the conversion. It lets you work with Minecraft text in a sane way.


What You're Actually Working With

Minecraft has three main text formats you'll encounter:

  • Legacy color codes - the §4Red §3Blue format. Easy to read, but limited.
  • JSON text components - Minecraft's newer format. More powerful, but verbose.
  • Votifier votes - server voting protocol messages that need formatting and transport.

The library handles Java Edition and Bedrock Edition differently (they use different color palettes), which is a detail most libraries miss.

So you might be building a voting plugin, a server status monitor, or a web-based server manager. You need to send formatted text to players, parse JSON from the server, or process votes. PHP-Minecraft handles all of it without you needing to understand Minecraft's internal text encoding.


Getting Started

Installation is straightforward if you're using Composer:

bash
composer require spirit55555/php-minecraft

Once installed, you can start using it immediately:

php
<?php
require 'vendor/autoload.php';
use \Spirit55555\Minecraft\MinecraftColors;

$text = '§4Red §3Blue §lBold §r';
echo MinecraftColors::convertToHTML($text);?>

The library supports both the § symbol (standard Minecraft format) and the & symbol (used in BungeeCord configs), so you'll work with whatever format your data comes in.


Color Codes and Server Messages

The most common use case is converting Minecraft color codes to HTML/CSS for web displays. If you're showing a server status page or building a web panel that displays the server's MOTD, you want those colors rendered properly. When setting up a server, you might use a Free Minecraft DNS to manage your server address, and then display a beautifully formatted MOTD on the web panel.

You can convert to plain HTML with inline styles, use CSS classes for styling, or even replace newlines with `
` tags all at once. Pick whichever output format fits your web stack.

There's also native support for the MOTD format (the text in server.properties), which is useful if you're reading or writing server configuration files programmatically. Want to programmatically update a server's MOTD? Parse it, modify it, and write it back using the same class. And if you're working with BungeeCord configurations instead, the library handles that too.


JSON Text Components

Modern Minecraft uses JSON for complex formatting. Commands send JSON back to players. Plugins generate JSON text with clickable links and hover text.

GitHub project card for Spirit55555/PHP-Minecraft
GitHub project card for Spirit55555/PHP-Minecraft

The MinecraftJSONColors class converts JSON text back to legacy format (which is sometimes what you need for backwards compatibility or logging). It's a less common operation than color code conversion, but when you need it, you really need it.

And v2.0.1 specifically fixed inheritance in JSON components. That's the kind of detail that matters if you're working with nested text components.


Votifier and Server Voting

The library includes votifier support for both v1 (public key) and v2 (token) protocols. If you're running a voting service or integrating votes into your server, you can send properly formatted votifier messages using PHP.

The library tries v2 first, then falls back to v1 automatically if needed. So you don't need to know which version the remote server supports.


Tips That Save Headaches

Start by testing locally. The conversion functions are pure PHP, so you can experiment in a script before integrating them into your application.

Remember that not all formatting works everywhere. Minecraft strips colors in certain contexts (like books), and Bedrock has a smaller color palette than Java Edition. Test what you actually need to support.

If you're storing formatted text in a database, consider storing the original format (whether it's JSON or legacy codes) rather than the HTML output. That way you can regenerate the HTML if you change your styling, and you're not locked into one output format.

The library is GPLv3, so make sure your project's license is compatible if you're building something commercial or proprietary.


When You Might Look Elsewhere

If you're building a game system or complex RPG mechanics, you probably want something heavier like Laravel's localization system. PHP-Minecraft is purposefully focused on text formatting and voting, not game logic.

For client-side Minecraft text rendering, you'd use JavaScript libraries instead. And if you need to parse Minecraft NBT data or interact with the game protocol, you're outside the scope of this library.

But for what it does, it's solid. 68 stars on GitHub, actively maintained, and it handles edge cases other libraries miss.

Spirit55555/PHP-Minecraft - GPL-3.0, ★68

Frequently Asked Questions

Do I need PHP-Minecraft if I'm not using PHP?
No. This library is specifically for PHP developers. If you're working in another language, you'll need a similar library for that language. It only works with PHP server software, plugins, or management tools.
Is PHP-Minecraft compatible with both Java and Bedrock Edition?
Yes, it handles both. Java Edition and Bedrock use different color systems and formatting codes. The library includes separate methods for each edition (convertToHTML vs convertToBedrockHTML), so your output works correctly on both platforms.
Can I use this in a production game server?
Absolutely. It's actively maintained, handles edge cases properly, and uses standard Minecraft protocols. Just make sure your project's license is compatible with GPL-3.0 if you're using it commercially or in a proprietary application.
What's the difference between legacy color codes and JSON text?
Legacy codes (§4Red) are simple but limited. JSON format is newer and supports clickable links, hover text, and more styling. PHP-Minecraft converts between them so you work with whichever format your data uses.
Does this replace BungeeCord's text formatting system?
Not exactly. BungeeCord uses ampersand (&) codes instead of section symbols (§). PHP-Minecraft supports both and can convert between them, so it complements BungeeCord configs rather than replacing them.