4 Legged League 3º Ciclo de apresentações do NEIIST (por Hugo Pereira)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP...
Transcript of Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP...
![Page 1: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/1.jpg)
Uni
cod
e a
nd
th
e U
nic
od
e lo
go a
re t
rad
em
ark
s o
f U
nic
od
e, I
nc.
, us
ed
with
per
mis
sio
n
ŬŋǐcøðΣPHP meets
Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005
![Page 2: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/2.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Agenda:
Porquê l10n/i18n? Desafios da l10n Introdução ao Unicode Implementação Actual (PHP 4/5) Implementação Futura (PHP 6)
Links Questões
![Page 3: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/3.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Agenda:
Porquê l10n/i18n? Desafios da l10n Introdução ao Unicode Implementação Actual (PHP 4/5) Implementação Futura (PHP 6)
Links Questões
![Page 4: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/4.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Porquê l10n/i18n?
There is more than one country in the world Ce n’est pas tout le monde qui parle anglais Tjueseks karakterer holder ikke mål Нот эврибади из юзин зэ сэйм скрипт ивэн 它变得更加复杂的与汉语语言
![Page 5: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/5.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Porquê l10n/i18n?
Suportar as línguas necessárias, sem rescrever a aplicação
Adicionar novos caracteres de forma transparente (por exemplo, €)
![Page 6: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/6.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Agenda:
Porquê l10n/i18n?Desafios da l10n Introdução ao Unicode Implementação Actual (PHP 4/5) Implementação Futura (PHP 6)
Links Questões
![Page 7: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/7.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Desafios da l10n
Diferenças nos charsets Multi-byte vs Single-byte encodings Diferentes algoritmos de sort, spelling,
dates, ...
![Page 8: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/8.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Exemplo: Sorting (aka Collation)
Em Lituano, o ‘y’ é ordenado entre ‘i’ e ‘k’ Em Espanhol Tradicional, ‘ch’ é tratado como
uma única letra, e é ordenado entre ‘c’ e ‘d’ Em Sueco, ‘v’ e ‘w’ são consideradas variantes
da mesma letra Em Alemão, ‘öf’ é ordenado antes de ‘of’. Nas
listas telefónicas é o contrário
![Page 9: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/9.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Exemplo: Capitalization
Grego: Σ ⇨ σ (no meio de uma palavra)
Grego: Σ ⇨ ς (no fim de uma palavra) Turco: i ⇨ İ, ı ⇨ I Alemão: ß ⇨ SS (lower[SS]=ss)
![Page 10: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/10.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Agenda:
Porquê l10n/i18n? Desafios da l10n Introdução ao Unicode Implementação Actual (PHP 4/5) Implementação Futura (PHP 6)
Links Questões
![Page 11: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/11.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Introdução ao Unicode
Suporta todas as línguas +100 mil caracteres 1 caracter != 1 byte Compatível com ASCII BOM (byte order mask) identifica a
codificação usada
![Page 12: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/12.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Termos técnicos (UTF-16)
Code point – representação de caracteres por números (U+1234)
Code unit – uma sequência de dois bytes Surrogates (high and low) – 2 code units
para representar o mesmo caracter (> FFFF)
![Page 13: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/13.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Codificação
UTF-7 (obsoleto) UTF-8 (até 4 bytes) UTF-16 (LE & BE) (2 ou 4 bytes) UTF-32 (LE & BE) (4 bytes) UTF-EBCDIC (até 5 bytes) ...
![Page 14: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/14.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Composição de caracteres
a + ˆ + . = ậU+0061 + U+0302 + U+0323 = U+1EAD
a + . + ˆ = ậU+0061 + U+0323 + U+0302 = U+1EAD
![Page 15: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/15.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Normalization
Caracteres equivalentes são reduzidos a uma forma standard (por exemplo os caracteres do ASCII estendido)
Facilita algoritmos
å != åU+00C5 + U+030A != U+0041
![Page 16: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/16.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Propriedades
Os caracteres têm propriedades, como:EspaçosLetras (lower/upper case)NúmerosPontuação ...
![Page 17: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/17.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Agenda:
Porquê l10n/i18n? Desafios da l10n Introdução ao Unicode Implementação Actual (PHP 4/5) Implementação Futura (PHP 6)
Links Questões
![Page 18: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/18.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Iconv
iconv_strlen() iconv_substr() iconv_strpos() iconv()
Não resolve a maioria dos problemas
![Page 19: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/19.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Mbstring
mb_strlen() mb_strpos() ...
Centrado em charsets Asiáticos Também não resolve a maioria dos
problemas
![Page 20: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/20.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Agenda:
Porquê l10n/i18n? Desafios da l10n Introdução ao Unicode Implementação Actual (PHP 4/5) Implementação Futura (PHP 6)
Links Questões
![Page 21: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/21.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
PHP 6
Detecção do encoding do script via BOM Overload das funções de forma
transparente Variáveis e nomes de funções em Unicode Suporte para Locales POSIX Utiliza a library da IBM: ICU UTF-16 internamente
![Page 22: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/22.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Settings
![Page 23: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/23.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Hello World
<?php
ini_set('unicode.output_encoding', 'iso-8859-1');
function こんにちは () { $世界 = 'Hello World!';
echo $世界 ; }
こんにちは ();
?>
![Page 24: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/24.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Sorting<?php
// the list of the strings to sort$array = array( 'caramelo', 'cacto', 'caçada');
// set our locale (Portuguese, in this case)i18n_loc_set_default('pt_PT');
// sort using the locale we previously setsort($array, SORT_LOCALE_STRING);
?>
![Page 25: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/25.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Normalization<?php
$GLOBALS["\u212B"] = '승인 ';
// U+00C5 = Å
echo $GLOBALS["\u00C5"];
?>
![Page 26: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/26.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
String types
binary – raw strings string – usa o encoding do script (for BC) unicode – UTF-16
![Page 27: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/27.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Binary vs Unicode<?php
$unicode = '傀傂两亨乄了乆刄 ';
$binary = b'傀傂两亨乄了乆刄 ';$binary2 = (binary) $unicode;
echo strlen($unicode); // 8echo strlen($binary); // 24echo strlen($binary2); // 24
var_inspect($unicode[2]); // unicode(1) "两 " { 4e24 }var_dump($binary[2]); // Ç
?>
![Page 28: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/28.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Escapes<?php
// '\Uxxxxxx' $str = 'U+123: \U000123';
// '\uxxxx' $str = 'U+123: \u0123';
// unicode(8) "U+123: ģ" var_dump($str);
?>
![Page 29: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/29.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Novas funções
unicode unicode_decode(input, encoding) string unicode_encode(input, encoding) string i18n_loc_get_default() bool i18n_loc_set_default(locale) text i18n_strtotitle(str) ...?
![Page 30: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/30.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Stream Filters
unicode.to.* - Unicode->String unicode.from.* - String->Unicode unicode.tidy.* - “magic” filter
![Page 31: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/31.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Agenda:
Porquê l10n/i18n? Desafios da l10n Introdução ao Unicode Implementação Actual (PHP 4/5) Implementação Futura (PHP 6)
Links Questões
![Page 32: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/32.jpg)
Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission
Links
www.php.net/unicode
http://www.derickrethans.nl/files/php6-unicode.pdf
http://www.gravitonic.com/do_download.php?download_file=talks/oscon2005/php_unicode_oscon2005.pdf
http://mega.ist.utl.pt/~ncpl/pres/
![Page 33: Unicode and the Unicode logo are trademarks of Unicode, Inc., used with permission ŬŋǐcøðΣ PHP meets Nuno Lopes, NEIIST – 4º Ciclo de Apresentações, 13/Outubro/2005.](https://reader034.fdocuments.net/reader034/viewer/2022042714/552fc132497959413d8d6270/html5/thumbnails/33.jpg)
Uni
cod
e a
nd
th
e U
nic
od
e lo
go a
re t
rad
em
ark
s o
f U
nic
od
e, I
nc.
, us
ed
with
per
mis
sio
n
ŬŋǐcøðΣPHP meets
Questões?Questões?