Hey everyone,
I have a small problem, I have the following script that replaces characters like ü, ö (German characters) with ue, oe, etc. Here is the script:
Note: not my code
I guess what it comes down to is this:
I input ü and it outputs ü. Does anyone know how to solve this? Maybe using the MultiByte extension? But AFAIK, it doesnt have a mb_str_replace(). I would really appreciate any help or suggestions.
Thank you.
Adding header("Content-type: text/html; charset=utf-8"); to the top of the file causes the script to work on my server. I don't know why though
[append]
The behavior is that the browser sends the form data in the same character set as the page that contained the form, and this is supported by this page, but I haven't found anything on W3C.
First, make sure you are explicitly setting the character encoding type. If you set it to UTF-8, then you only have to handle one case.
Second, make sure your file is saved in UTF-8.
Then it will work.
Reason:
The character: "ö" might be stored as 0xF6 (ASCII) or 0xC3B6 (UTF-8) or 0x00F6 (UTF-16) or 0x000000F6 (UTF-32) in your file.
In addition to those types, the browser may submit it as ö or ö or ö. (Although for characters < 256, the default is probably always ASCII.)
A naive search and replace will only work if both encoding types are the same.
Maybe if you stopped killing kittens your code would work
My advice: use UTF-8 for everything. This includes:
- The source file itself
- PHP's multibyte support (mb_encoding() etc.)
- The database collation (if possible)
- Content-type header