Reputation: 415
I've ran into an issue with special characters being used as variables.
Heres my HTML that has something to do with characters:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
...
<form class="nav-search left" method="POST" enctype="application/x-www-form-urlencoded">
<input name="summoner_name" type="text" placeholder="Summoner Name" required autofocus />
</form>
Heres the PHP which is trying to get the $_POST
:
$summoner = htmlspecialchars($_POST['summoner_name']);
$summoner_name = strtolower($summoner);
-> outputs nothing, as it isn't read properly.
Letters such as Śý
will be used, and I think these are from extended-latin
Upvotes: 0
Views: 121
Reputation: 10508
Using this walkthrough as a jumping off point, I would say:
...verify that your application is emitting the Content-Type: text/html; charset=utf-8
header. There's really no reason not to, and it's really simple.
...the first place you may have a real issue is your form. Again referencing the above link the encoding to be used for application/x-www-form-urlencoded data is practically undefined.
Make sure your form is using the attribute accept-charset
set to "utf-8"
(accept-charset="utf-8"
).
...If you aren't using a database in here, then there's nothing to do there, but if you ever store this data in a database, that's almost definitely where the mis-encoding is happening.
There's a lot that could go wrong in the database - from connecting, to how the data is stored, to how the data is retrieved. If you are using a database at all to store this data before it is sent back to the browser, take extra care to make sure the database is properly encoding and retrieving UTF-8 text.
...strtolower
doesn't convert characters not represented by your locale. If your locale is, say, en-US
, your special UTF-8
characters will not be converted, and you'll get an empty string (if there aren't any other characters).
If you were to use mb_strtolower
, you could pass an encoding like: mb_strtolower($summoner, 'UTF-8');
This properly handles special characters.
Upvotes: 1