What is Character Encoding & UTF-8?

A character encoding maps characters to bytes. UTF-8 is the variable-width encoding of Unicode: ASCII characters take one byte, other characters take two to four. Because it can represent every Unicode character while staying byte-compatible with ASCII, UTF-8 has become the default across the web stack, and any multilingual application should treat it as non-negotiable end to end.

End to end means every layer: source files, HTTP responses, the database connection, and the database columns themselves. A mismatch anywhere produces mojibake, the familiar é garbage, or silently truncated text. For MySQL specifically, use the utf8mb4 charset, since the legacy charset MySQL calls utf8 stores at most three bytes per character and rejects emoji and other supplementary-plane characters. Laravel's default database configuration already does this.

In PHP, remember that native string functions count bytes, not characters. Use the mbstring functions (mb_strlen, mb_substr) or Laravel's Str helpers when working with user-visible text, or lengths and truncation will be wrong exactly for the non-English content localization introduces.

// config/database.php (mysql connection)
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',

mb_strlen('héllo');  // 5 characters
strlen('héllo');     // 6 bytes

Put the theory to work

LangSyncer manages your Laravel translations live: import lang files, translate with AI and publish without a deploy.

We use cookies to improve your experience and analyze site traffic. Cookie Policy

Cookie Preferences

Essential

Required for the site to work

Analytics

Help us improve the site

Marketing

Personalized ads and content