Characterset

1,489 views

Published on

Dealing with UTF-8 and character set .

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
1,489
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
6
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Characterset

  1. 1. Character set <ul>Hari K T Bridge India http://harikt.com Twitter : @harikt </ul>
  2. 2. Problem ? <ul><li>Seeing ? -> �
  3. 3. :-(
  4. 4. Solution ?
  5. 5. :-) </li></ul>
  6. 6. UTF-8 <ul><li>originally proposed by Dave Prosser
  7. 7. subsequently modified by Ken Thompson
  8. 8. To be backward-compatible with ASCII
  9. 9. To enable encoding of up to at least 231 characters (the theoretical limit of the first draft proposal for the Universal Character Set).
  10. 10. http://www.cl.cam.ac.uk/~mgk25/ucs/utf-8-history.txt </li></ul>
  11. 11. When and where ? <ul><li>Dealing with i18n and L10n </li></ul>
  12. 12. How to do ? <ul><li><meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; />
  13. 13. Must be the first thing to be in <head>
  14. 14. Remember Google UTF-7 exploit read on http://shiflett.org/archive/178
  15. 15. Changing the server encoding </li></ul>
  16. 16. Server encoding <ul><li>PHP header function
  17. 17. header('Content-Type:text/html; charset=UTF-8');
  18. 18. php.ini
  19. 19. default_charset = &quot;utf-8&quot;
  20. 20. ini_set('default_charset', 'UTF-8');
  21. 21. Running php as a module in apache and not fast cgi
  22. 22. php_value default_charset &quot;UTF-8&quot;
  23. 23. AddDefaultCharset UTF-8 in .htaccess </li></ul>
  24. 24. Force the forms <ul><li>Add accept-charset .
  25. 25. Eg :
  26. 26. <form accept-charset=&quot;utf-8&quot; ...> </li></ul>
  27. 27. MySql <ul><li>DB utf8_general_ci
  28. 28. mysql_set_charset('utf8');
  29. 29. mysqli_set_charset('utf8');
  30. 30. Remember we are moving to PDO ;)
  31. 31. $handle = new PDO(&quot;mysql:host=localhost;dbname=dbname&quot;,
  32. 32. 'username', 'password',
  33. 33. array (PDO::MYSQL_ATTR_INIT_COMMAND => &quot;SET NAMES utf8&quot;)); </li></ul>
  34. 34. Inside Zend Framework <ul><li>$params = array( 'host' => 'localhost', </li><ul><li>'username' => 'username',
  35. 35. 'password' => 'password',
  36. 36. 'dbname' => 'dbname',
  37. 37. 'driver_options' => array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8 ;')
  38. 38. ); </li></ul><li>$db = Zend_Db::factory(' PDO_MYSQL ', $params);
  39. 39. Or in config/application.ini
  40. 40. resources.db.params.charset = utf8 </li></ul>
  41. 41. With Symfony2 ? <ul><li>In app/config/config.yml
  42. 42. # Doctrine Configuration
  43. 43. doctrine:
  44. 44. dbal:
  45. 45. driver: %database_driver%
  46. 46. host: %database_host%
  47. 47. port: %database_port%
  48. 48. dbname: %database_name%
  49. 49. user: %database_user%
  50. 50. password: %database_password%
  51. 51. charset: UTF8 </li></ul>
  52. 52. Samples <ul><li>Sample application ;)
  53. 53. Show size of byte with utf-8 and latin charcter-set.
  54. 54. EXPLAIN SELECT * FROM tbl WHERE first_name LIKE 'joshua'; </li></ul>
  55. 55. Questions ?
  56. 56. References <ul><li>http://www.joelonsoftware.com/articles/Unicode.html
  57. 57. http://htmlpurifier.org/docs/enduser-utf8.html
  58. 58. http://en.wikipedia.org/wiki/UTF-8
  59. 59. http://webcollab.sourceforge.net/unicode.html
  60. 60. http://akrabat.com/php/utf8-php-and-mysql/
  61. 61. http://www.adayinthelifeof.nl/2010/12/04/about-using-utf-8-fields-in-mysql </li></ul>

×