October 27, 200916 yr At the moment, I have to disallow diacritical characters in all of my forms because PHP does not correctly handle multi-byte Unicode characters. This is not very user-friendly, particularly if one of your clients has a lot of customers in Scandinavia... Forcing users to enter letters without diacritics is basically forcing them to misspell words. I have read hints of three possible workarounds: wait for PHP6 (not ideal); write a regex that can replace Unicode characters with ASCII; or use a function called MBstring. Of the last two, which is most suitable and how would I do it? Or is there a still better solution?
October 31, 200916 yr Author I didn't think that this would be that hard to answer. This must be an issue that other developers have encountered.
November 1, 200916 yr Author Your speaking Scandinavian mate which is not a language i know, sorry :s. Thanks for the not-at-all-helpful comment. Incidentally, you do know that Scandinavian is not a language but a region comprising four countries, right? It is not as if diacritics are uncommon, since they are used in German, French, Spanish, Portuguese, even English... so surely this must be a common enough problem and somebody knows what the best solution is. Blocking all diacritics from form data is currently my only way of preventing errors in the output, but it is not helpful to users, so I need an alternative.
November 2, 200916 yr Hi Ade Sorry for the late response I've been out of action for a while. Looking at it I'd use mb_convert_encoding(), example below: <?php echo mb_convert_encoding('ÖÄÜöäü', "UTF-8"); ?> Let me know if this helps you BenTheDesigner
November 11, 200916 yr I'd recommend storing it all as UTF-8 as that way you're able to handle all languages. First of all add a UTF-8 header to your HTML file. Secondly you need to make sure if you're storing the data in a database that you have the encoding of that field set to UTF-8 Unicode. You then should look at the Multibyte functions built into default installations of PHP. http://www.php.net/manual/en/ref.mbstring.php To help you in making sure your script is utf-8 friendly i'll need to see it, however, the above should be enough to sort you out.
November 13, 200916 yr Author I'd recommend storing it all as UTF-8 as that way you're able to handle all languages. First of all add a UTF-8 header to your HTML file. Secondly you need to make sure if you're storing the data in a database that you have the encoding of that field set to UTF-8 Unicode. You then should look at the Multibyte functions built into default installations of PHP. http://www.php.net/manual/en/ref.mbstring.php To help you in making sure your script is utf-8 friendly i'll need to see it, however, the above should be enough to sort you out. Thanks for replying, but I rarely need to deal with databases. I leave that to MySQL specialists and stick to my own specialisms. This is about e-mail output. Including a UTF-8 dec is "web 101" and has no effect here anyway. If it did, I would not have this issue.
November 13, 200916 yr Hi Ade Any luck with my solution? Have you managed to solve your problem yet? BenTheDesigner
November 13, 200916 yr Thanks for replying, but I rarely need to deal with databases. I leave that to MySQL specialists and stick to my own specialisms. This is about e-mail output. Including a UTF-8 dec is "web 101" and has no effect here anyway. If it did, I would not have this issue. Sorry didn't read your email correctly. If you use mb_send_mail your problem should be solved. http://uk2.php.net/manual/en/function.mb-send-mail.php
November 13, 200916 yr Author Ben, Kieran - not quite solved. I looked briefly at the various mb functions but they are not well explained in the PHP manual (like the rest of its content). As I have a lot of work on, I may have to leave this unresolved and outsource it at a later date.
November 21, 200916 yr Author This seems to be fully sorted now. I added a header to set the content type to utf-8 (by default, the e-mails were being encoded in 8891-1) and that has preserved all special characters correctly. A simple solution, after all!
Create an account or sign in to comment