beerguide_au Posted March 5, 2007 Share Posted March 5, 2007 I have an input form which needs to be able to handle umlauts (eg: ä ö etc..) and passes them via POST to a php file I have created. In my php file I have the following code: // Convert accents and extended characters into english equivalents. $characters = array( "'" => "", "&" => "And", "(" => "", ")" => "", "-" => " " ); $umlauts = array( "ä" => "ae", "ö" => "oe", "ü" => "ue", "ß" => "ss" ); $replacements = array_merge( $characters, $umlauts ); $beer_name = strtr( strip_tags( trim( $_POST['beer_name'] ) ), $replacements ); In my header I have the following code to allow/force utf-8: // Setting the Content-Type header with charset header('Content-Type: text/html; charset=utf-8'); When I try to echo any content, or use it in a mysql table the $characters part is correct and is converting things like the & to And, but the umlauts section is ignored and ä etc.. is echo'd to the screen instead of the converted string, in this case 'ae'. This leads me to think it has something to do with either how the form is handling the POST content and/or I'm using an incorrect character set? Can anyone please help me with this issue? It would be much appreciated. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 There's a lot of messy character set issues here.. first thing to do is just to echo $_POST['beer_name'] and see what you get. Make sure that you look at the source of the page rather than the rendered output (go to View -> View Source or the equivalent in your browser). There are many different ways of encoding a character, and if the encodings don't match exactly, the strtr() will not work. I suspect your problem is that the characters have been urlencoded, as in the functions urlencode() and urldecode(). Quote Link to comment Share on other sites More sharing options...
beerguide_au Posted March 5, 2007 Author Share Posted March 5, 2007 Thank you for the speedy reply. I have viewed the source (im using IE 7) and I have the following: Test & Weißbier<br /> (Noting the ß is displayed like that in the source, as entered into the form originally) I too have a feeling it is a matching issue as the $characters array works, so the function strtr is working for non $umlauts entities. Is there a way I can display exactly what the form is seeing the POST other than 'viewing html source' through a browser? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.