Fix Garbled Form Input in PHP: UTF-8 and mbstring
Publication Date:
Updated:
INFORMATION > Fix Garbled Form Input in PHP: UTF-8 and mbstring
Bottom line: Keep one explicit encoding—normally UTF-8—across the HTML form, HTTP response, PHP source, string handling, and database connection. Capture the raw input and identify the boundary where bytes are decoded incorrectly before changing global settings.
What you'll learn
- How to distinguish a display problem from input conversion or database corruption.
- Which headers and PHP settings are relevant to modern UTF-8 applications.
- Why the legacy
mbstring.internal_encodingandmbstring.http_inputrecipe below should not be copied to a current deployment.
Who this is for: PHP maintainers troubleshooting mojibake after form validation, redirects, or database round trips.
2026 context: PHP deprecated the old iconv/mbstring encoding directives in PHP 5.6 in favor of default_charset; modern code should make encoding explicit at each boundary. The original configuration is retained only to explain the historical incident.
Overview
Garbled characters occurred when transitioning from the input screen to the confirmation screen in PHP.
Garbled text occurs when moving to the confirmation screen after entering text in the form. Garbled characters also occur when moving to the self screen due to an input check error. Since the server had just been built, I felt that something was missing from the PHP configuration, so I will describe what I found out at that time.
Table of Contents
1. Diagnose where the encoding changes
The following information was investigated to determine the cause of the problem.
1-1. survey
First, check the PHP settings (php.ini).
default_charset = "UTF-8"
mbstring.internal_encoding = UTF-8
mbstring.encoding_translation = On
The above is the case, and it looks OK. However, I could not identify the problem in the PHP source.
Once again, I checked php.ini for suspicious settings and found one suspicious setting.
mbstring.http_input = auto
It was unclear whether it was encoded in UTF-8 since it was set to "auto", so I changed it as follows to try it out.
mbstring.http_input = UTF-8
Garbled characters are resolved successfully. This setting is for the mbstring module, which is required when using multibyte strings in PHP. This is a setting for encoding received http requests.
2. Conclusion
If you encounter garbled characters, suspect the following settings in php.ini. The default setting is "auto", so please check this when using mbstring to process multibyte strings.
Official references
■INFORMATION
■PROFILE
■CONTACT