0

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

zxc
  • 415
  • 3
  • 17
  • 2
    What does a simple `var_dump($_POST)` show? – deceze Aug 21 '14 at 13:24
  • I believe this question is answered here: http://stackoverflow.com/questions/11886954/how-to-post-special-reserved-characters-from-html-forms-to-php-pages?rq=1 – Bob Brown Aug 21 '14 at 13:32

1 Answers1

1

Using this walkthrough as a jumping off point, I would say:

First

...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.

Next

...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").

One More

...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.

Finally

...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.

rockerest
  • 10,412
  • 3
  • 37
  • 67
  • so i've done `` & `` & `
    ` but it still doesn't seem to work, and yes - my website isn't using a database at the moment.
    – zxc Aug 21 '14 at 14:26
  • Check out my edit. You're using a function that (most likely) will drop any special characters. – rockerest Aug 21 '14 at 14:35