SlideShare a Scribd company logo
1 of 69
Download to read offline
Andrei Zmievski
                                                 Chief Architect
                                                  Outspark, Inc




       PHP for Grown-ups
          How 5.3, 6, and intl will change your life




CONAPHP Brasil
PHP 6 = PHP 5 + Unicode
PHP 5 = PHP 6 -- Unicode
Unicode = PHP 6 -- PHP 5
What is PHP?
    Ha. Ha.
What is Unicode?
    and why do I need?
mojibake
mojibake
         phenomenon of incorrect, unreadable
    characters shown when computer software
fails to render a text correctly according to its
                associated character encoding
mojibake
mojibake
Unicode
 provides a unique number
    for every character:

no matter what the platform,

no matter what the program,

no matter what the language.
unicode standard

Developed by the Unicode Consortium
Covers all major living scripts
Version 5.0 has 99,000+ characters
Capacity for 1 million+ characters
Widely supported by standards & industry
generative
Composition can create “new” characters
Base + non-spacing (combining) character(s)

              A    + ˚ = Å
         U+0041 + U+030A = U+00C5


              a + ˆ + . = ậ
     U+0061 + U+0302 + U+0323 = U+1EAD


              a + ̢ +    ̌ = ǎ̢
        U+0061 + U+0322 + U+030C = ?
unicode != i18n



Unicode simplifies development
Unicode does not fix all
internationalization problems
definitions

Internationalization                        I18n
To design and develop an application:
   ✓
    without built-in cultural assumptions
   ✓
 that is efficient to localize

Localization                                L10n
To tailor an application to meet the needs of a
particular region, market, or culture
localized data


date/time formats
numbers, currency
sorting
and more
locale data


I18N and L10N rely on consistent
and correct locale data
Problem with POSIX locales: not
always consistent or correct
CLDR
Hosted by Unicode Consortium

Goals:
 Common, necessary software locale data for all world
 languages
 Collect and maintain locale data
 XML format for effective interchange
 Freely available

Latest release: July 2008 (CLDR 1.6)

374 locales, with 137 languages and 140 territories
PHP 6
unicode support


Everywhere: engine, extensions, API
Native and complete
Uses industry-standard ICU library
sample
    Grab first 5 titles from Reuters China feed,
    clean up, and send out as JSON
$xml = simplexml_load_file(

   
   'http://feeds.feedburner.com/reuters/CNTbusinessNews/');

$titles = array();
$i = 0;
foreach ($xml->channel->item as $item) {
    // each title looks like this:
    $title = preg_replace('!p{Ps}.*p{Pe}s*!', '', $item->title);
    $titles[] = $title;
    if (++$i == 5) break;
}

echo json_encode($titles);
string types
Unicode
 text
 default for literals, etc
Binary
 bytes
 everything ∉ Unicode type
string types



internal processing: Unicode
interface to outside world: binary
Conversions
                                                        streams
   Dataflow                            stream-specific
                                         encodings

                            PHP
                           Unicode
                           strings
Web                     runtime encoding                    Web
                            binary
“HTTP input encoding”                        HTTP output encoding
                            strings




  script encoding                                filesystem encoding
            scripts                        filesystem
strings
String literals are Unicode

  $str = quot;Hello, world!quot;;
 // Unicode string
  echo strlen($str);
 
 
 // result is 13


  $jp = quot;           quot;;
   // Unicode string
  echo strlen($jp);
 
                   
      // result is 7
strings
String offsets work on code points


$str = quot;      quot;;
 
 // 2 code points
echo $str[1];
 
 // result is
$str[0] = '    ';
 full string is now
                 //
identifiers
Unicode identifiers are allowed

class                {
   function ᓱᓴᓐ ᐊᒡᓗᒃᑲᖅ
 { ... }
                       
   function !வா$ கேனச)

{ ... }
   function འquot;ག་%ལ།
 
 { ... }
                   
}

$        = array();
$       [‘‫ = ]’ַרעְיולּוחַ ׁשָנָה‬new   ();
functions
    Functions understand Unicode text
    strtoupper() and friends do proper case mapping
$str = strtoupper(quot;fußballquot;);
 // result is FUSSBALL

$str = strtolower(quot;ΣΕΛΛΆΣquot;);
       // result is σελλάς


    strip_tags() works on complex text
$str = strip_tags(quot;     <span>είναι</span>   quot;);



    strrev() preserves combining sequences
$u = quot;Vieu0302u0323t Namquot;;
       // Việt Nam
$str = strrev($u); 
 
      
   
   // result is maN tệiV,

   
   
   
   
   
   
   
   
   // not maN ṭ̂eiV
streams
Built-in support for converting between
Unicode strings and other encodings on the
fly
Reading from a UTF-8 text file:
$fp = fopen('somefile.txt', 'rt'); 
$str = fread($fp, 100); // returns 100 Unicode characters 



Writing to a UTF-8 text file:
$fp = fopen('somefile.txt', 'wt'); 
fwrite($fp, $uni); // writes out data in UTF-8 encoding 
streams
 Default encoding:
stream_default_encoding('Shift-JIS');
$data = file_get_contents('somefile.txt', FILE_TEXT);
// ... work on $data ...
file_put_contents('somefile.txt', $data, FILE_TEXT);



 Custom contexts:
$ctx = stream_context_create(NULL,
                array('encoding' => 'big5'));
$data = file_get_contents('somefile.txt', FILE_TEXT, $ctx); 
// ... work on $data ...
file_put_contents('somefile.txt', $data, FILE_TEXT, $ctx);
text iterator

Use it when iterating over text in a linear
fashion (instead of [] operator)
Iteration over code points, characters,
graphemes, words, lines, and sentences
forward and backward
Also provides ICU’s boundary analysis API
text iterator
Iterate over characters
  $text = quot;naiu308vequot;; // rendered as naïve
  foreach (new TextIterator($text,
  
 
 
 TextIterator::CHARACTER) as $u) {
      var_inspect($u);
  }



Result
  unicode(1)   quot;nquot;   {   006e   }
  unicode(1)   quot;aquot;   {   0061   }
  unicode(2)   quot;ïquot;   {   0069   0308 }
  unicode(1)   quot;vquot;   {   0076   }
  unicode(1)   quot;equot;   {   0065   }
text iterator
Iterate over words in reverse order
  $text = quot;Pouvez-vous me dire quelle heure il est ? Merci.quot;;
  foreach (new ReverseTextIterator($text,
  
   
   
   
  
   TextIterator::WORD) as $u) {
      if ($u != quot; quot;) echo($u),quot;nquot;;
  }


Result
  .
  Merci
  ?
  est
  il
  heure
  quelle
  dire
  me
  vous
  -
  Pouvez
text iterator
Truncate text at a word boundary
  $it = new TextIterator($text, TextIterator::WORD);
  $offset = $it->preceding(40);
  echo substr($text, 0, $offset), quot;...nquot;;



Get the last 2 sentences of the text
  $it = new TextIterator($text, TextIterator::SENTENCE);
  $it->last();
  $offset = $it->previous(2);
  echo substr($text, $offset);



Get all the pieces delimited by boundaries
  $it = new TextIterator($text, TextIterator::WORD);
  $words = $it->getAll();
text transforms

Powerful and flexible way to process Unicode text
 script-to-script conversions
 normalization
 case mappings and full-/halfwidth conversions
 accent removal
 and more

Allows chained transforms
[:Latin:]; NFKD; Lower; Latin-Katakana;
transliteration
$names = quot;
    , 
    , 
       , 
        , 
  Горбачев, Михаил
  Козырев, Андрей
  Καφετζόπουλος, Θεόφιλος
  Θεοδωράτου, Ελένη
quot;;
$r = strtotitle(str_transliterate($names, quot;Anyquot;, quot;Latinquot;));


Gim, Gugsam
Gim, Myeonghyi
Takeda, Masayuki
Oohara, Manabu
Gorbačev, Mihail
Kozyrev, Andrej
Kaphetzópoulos, Theóphilos
Theodōrátou, Elénē
transliteration
Here’s how to get (a fairly reliable) Japanese
pronunciation of your name

$k = str_transliterate('Britney Spears', 'Latin', 'Katakana');
echo($k),quot;nquot;;
$l = strtotitle(str_transliterate($k, 'Katakana', 'Latin'));
echo($l),quot;nquot;;




Buritenei Supearusu
other things
APC bundled

PCRE default regex engine

“taint” mode

traits

a couple of syntactic sugar treats

64-bit integer type

general cleanup
pecl/intl
features
Locales
Collation
Number and Currency Formatters
Date and Time Formatters
Time Zones
Calendars
Message Formatter
Choice Formatter
Resource Handler
Normalization
versioning

Works under PHP 5 and 6
Uses native strings in PHP 6
Requires UTF-8 strings in PHP 5
Can use mbstring, iconv
Collator
comparing strings
compare($str1, $str2) = -1,0,1


$coll = new Collator(quot;fr_CAquot;);
if ($coll->compare(quot;côtequot;, quot;cotéquot;) < 0) {
    echo quot;lessnquot;;
} else {
    echo quot;greaternquot;;
}




               côte < coté
sorting strings
sort($array, $flags)
asort($array, $flags)
sortWithSortKeys($array)
$strings = array(
        quot;cotequot;, quot;côtequot;, quot;Côtequot;, quot;cotéquot;,
        quot;Cotéquot;, quot;côtéquot;, quot;Côtéquot;, quot;coterquot;);
$coll = new Collator(quot;fr_CAquot;);
$coll->sort($strings);

cote
côte
Côte
coté
Coté
côté
Côté
coter
strength control
setStrength($strength)
getStrength()

$coll = new Collator(quot;fr_CAquot;);
$coll->setStrength(Collator::PRIMARY);
if ($coll->compare(quot;côtequot;, quot;cotéquot;) == 0) {
    echo quot;samenquot;;
} else {
    echo quot;differentnquot;;
}


               côte = coté
NumberFormatter
what it is

allows formatting numbers as strings
according to the localized format or
given pattern or set of rules
and parsing strings into numbers
according to these patterns
replacement for number_format()
formatter styles
        123456.789 in en_US

NumberFormatter::PATTERN_DECIMAL
123456.79 (with ##.##)

NumberFormatter::DECIMAL
123456.789

NumberFormatter::CURRENCY
$123,456.79

NumberFormatter::PERCENT
12,345,679%
formatter styles
             123456.789 in en_US

NumberFormatter::SCIENTIFIC
1.23456789E5

NumberFormatter::SPELLOUT
one hundred and twenty-three thousand, four hundred and
fifty-six point seven eight nine

NumberFormatter::ORDINAL
123,457th

NumberFormatter::DURATION
34:17:37
formatting

  format($number [, $type])


$fmt = new NumberFormatter(‘en_US’,
                           NumberFormatter::DECIMAL);
$fmt->format(1234);
// result is 1,234

$fmt = new NumberFormatter(‘de_CH’,
                           NumberFormatter::DECIMAL);
$fmt->format(1234);
// result is 1'234
MessageFormatter
what it is


produces concatenated messages in a
language-neutral way
operates on patterns, which contain
subformats
what it is

 Need to get:
          Today is November 21, 2007.

 Normal PHP way:        date(‘F d, Y’)

 MessageFormat would use
pattern: Today is {0,date}.
arg: array(time())
formatting

  format($args)


$pattern = “On {0,date} you have {1,number} meetings.”;
$args = array(time(), 2);
$fmt = new MessageFormatter(‘en_US’, $pattern);
echo $fmt->format($args);

// On November 22, 2007 you have 2 meetings.
formatting

    Trying different locales

$fr_pattern = quot;Aujourd''hui, {0,date,dd MMMM},
               il y a {1,number} personnes sur {3}.quot;;
$fr_args = array(time(), 6579844000.0, 3, quot;la Terrequot;);

$msg = new MessageFormatter('fr_FR', $fr_pattern);
echo $msg->format($fr_args);

// Aujourd'hui, 22 novembre, il y a 6 579 844 000 personnes sur
la Terre.
php 5.3
namespaces


designed to solve scoping problems
perhaps the most discussed issue
ever on the internals list
complex topic - still under work
namespaces
Definition
namespace Yahoo::News;
class Dir {
    ...
}


Usage
// directly
$foo = new Yahoo::News::Dir;

// import namespace
use Yahoo::News;
$foo = new News::Dir;

// rename class
use Yahoo::News::Dir as YND;
$foo = new YND;

// use global class
$foo = new ::Dir;
lambdas and closures
  anonymous functions
  scope capture
  should be familiar to JS users
  $lambda = function () { 
      echo quot;Hello World!nquot;;
  };
  $lambda();
lambdas and closures
   more complex example
 function getAdder($x) {
     return function ($y) use ($x) {
         return $x + $y;
     };
 }

 $adder = getAdder(10);
 print_r( array_map( $adder, array(1, 2, 3) ) );

 Array
 (
     [0] => 11
     [1] => 12
     [2] => 13
 )
phar


PHp ARchive
PharData = PDO for tar and zip
files
encapsulated applications
PharData

phar = new PharData('project.tar');

// add all files in the project
$phar->buildFromDirectory('./project');

// now compress it
$phar->convertToData(PHAR::TAR, PHAR::GZ);
php archives
   access file in archive
 include 'phar:///path/to/myphar.phar/file.php';




   host an entire application
// create app archive
$phar = new Phar('myphar.phar');
$phar['cli.php']   = '<?php echo quot;Hello CLI Worldquot;; ?>';
$phar['index.php'] = '<?php echo quot;Hello Web Worldquot;; ?>';
$phar->setDefaultStub('cli.php', 'index.php');
extensions

intl
fileinfo
sqlite3
mysqlnd
other

garbage collection
NOWDOC
limited GOTO
ternary shortcut ?:
numerous fixes, additions, and
cleanups
obrigado

http://gravitonic.com/talks

More Related Content

What's hot

Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Benjamin Bock
 
Ruby on Rails For Java Programmers
Ruby on Rails For Java ProgrammersRuby on Rails For Java Programmers
Ruby on Rails For Java Programmerselliando dias
 
Disregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDisregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDaniel Cousineau
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with RailsClinton Dreisbach
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
 
Fonts in the Age of the Interface
Fonts in the Age of the InterfaceFonts in the Age of the Interface
Fonts in the Age of the InterfaceClint Schnee
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Wen-Tien Chang
 
Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13Rafael Dohms
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Ajay Khatri
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介Wen-Tien Chang
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationguest5d87aa6
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using phpRishabh Srivastava
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)Ajay Khatri
 

What's hot (20)

Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
 
Lca05
Lca05Lca05
Lca05
 
Ruby on Rails For Java Programmers
Ruby on Rails For Java ProgrammersRuby on Rails For Java Programmers
Ruby on Rails For Java Programmers
 
Disregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_FormDisregard Inputs, Acquire Zend_Form
Disregard Inputs, Acquire Zend_Form
 
7.1.intro perl
7.1.intro perl7.1.intro perl
7.1.intro perl
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with Rails
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
gonzalo
gonzalogonzalo
gonzalo
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
 
Fonts in the Age of the Interface
Fonts in the Age of the InterfaceFonts in the Age of the Interface
Fonts in the Age of the Interface
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using php
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 

Viewers also liked

Sending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHPSending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHPManuel Lemos
 
Welcome To The Library
Welcome To The LibraryWelcome To The Library
Welcome To The Librarybhodes
 
Succeeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects PresentationSucceeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects PresentationTerry Freedman
 
Space Oddity Andrew Kolb
Space Oddity Andrew KolbSpace Oddity Andrew Kolb
Space Oddity Andrew KolbDaniel Vak
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsManuel Lemos
 
Pubblicita Playboy
Pubblicita PlayboyPubblicita Playboy
Pubblicita Playboypc1951
 
FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012Nouh Walid
 
Bodypaintingworld
BodypaintingworldBodypaintingworld
Bodypaintingworldpc1951
 
Masterpiece Video Productions
Masterpiece Video ProductionsMasterpiece Video Productions
Masterpiece Video Productionsmasterpiecevideo
 
One year of FusionInventory
One year of FusionInventoryOne year of FusionInventory
One year of FusionInventoryNouh Walid
 
Continuing Professional Development
Continuing Professional DevelopmentContinuing Professional Development
Continuing Professional DevelopmentTerry Freedman
 
What Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On WindowsWhat Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On WindowsManuel Lemos
 
GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011Nouh Walid
 
I Am The Future Of Journalism Because
I Am The Future Of Journalism BecauseI Am The Future Of Journalism Because
I Am The Future Of Journalism BecauseTerry Freedman
 
Rifiuti E Inceneritori
Rifiuti E InceneritoriRifiuti E Inceneritori
Rifiuti E Inceneritoripc1951
 

Viewers also liked (18)

簡報2
簡報2簡報2
簡報2
 
Sending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHPSending E-mail that reaches the destination using PHP
Sending E-mail that reaches the destination using PHP
 
Welcome To The Library
Welcome To The LibraryWelcome To The Library
Welcome To The Library
 
Succeeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects PresentationSucceeding With Web 2 Projects Presentation
Succeeding With Web 2 Projects Presentation
 
Space Oddity Andrew Kolb
Space Oddity Andrew KolbSpace Oddity Andrew Kolb
Space Oddity Andrew Kolb
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
 
Pubblicita Playboy
Pubblicita PlayboyPubblicita Playboy
Pubblicita Playboy
 
PHP In Brazil
PHP In BrazilPHP In Brazil
PHP In Brazil
 
FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012FusionInventory at LSM/RMLL 2012
FusionInventory at LSM/RMLL 2012
 
Bodypaintingworld
BodypaintingworldBodypaintingworld
Bodypaintingworld
 
Masterpiece Video Productions
Masterpiece Video ProductionsMasterpiece Video Productions
Masterpiece Video Productions
 
One year of FusionInventory
One year of FusionInventoryOne year of FusionInventory
One year of FusionInventory
 
Continuing Professional Development
Continuing Professional DevelopmentContinuing Professional Development
Continuing Professional Development
 
簡報2
簡報2簡報2
簡報2
 
What Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On WindowsWhat Could Microsoft Do To Make PHP Run Better On Windows
What Could Microsoft Do To Make PHP Run Better On Windows
 
GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011GLPI talk at FOSDEM 2011
GLPI talk at FOSDEM 2011
 
I Am The Future Of Journalism Because
I Am The Future Of Journalism BecauseI Am The Future Of Journalism Because
I Am The Future Of Journalism Because
 
Rifiuti E Inceneritori
Rifiuti E InceneritoriRifiuti E Inceneritori
Rifiuti E Inceneritori
 

Similar to PHP for Grown-ups

Developing Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and JavascriptDeveloping Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and JavascriptJeff Haynie
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 
Voicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoxeo Corp
 
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...grosser
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash CourseWill Iverson
 
Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)Chhom Karath
 
How To Build And Launch A Successful Globalized App From Day One Or All The ...
How To Build And Launch A Successful Globalized App From Day One  Or All The ...How To Build And Launch A Successful Globalized App From Day One  Or All The ...
How To Build And Launch A Successful Globalized App From Day One Or All The ...agileware
 
Employing Custom Fonts
Employing Custom FontsEmploying Custom Fonts
Employing Custom FontsPaul Irish
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentalsrspaike
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9tomaspavelka
 
The Real Time Web with XMPP
The Real Time Web with XMPPThe Real Time Web with XMPP
The Real Time Web with XMPPJack Moffitt
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applicationsamichoksi
 
Corporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 Tokyo
Corporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 TokyoCorporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 Tokyo
Corporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 TokyoYusuke Kawasaki
 

Similar to PHP for Grown-ups (20)

Developing Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and JavascriptDeveloping Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and Javascript
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Voicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.com
 
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash Course
 
Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
 
How To Build And Launch A Successful Globalized App From Day One Or All The ...
How To Build And Launch A Successful Globalized App From Day One  Or All The ...How To Build And Launch A Successful Globalized App From Day One  Or All The ...
How To Build And Launch A Successful Globalized App From Day One Or All The ...
 
Employing Custom Fonts
Employing Custom FontsEmploying Custom Fonts
Employing Custom Fonts
 
php
phpphp
php
 
Unicode 101
Unicode 101Unicode 101
Unicode 101
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentals
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9
 
Api Design
Api DesignApi Design
Api Design
 
The Real Time Web with XMPP
The Real Time Web with XMPPThe Real Time Web with XMPP
The Real Time Web with XMPP
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applications
 
Corporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 Tokyo
Corporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 TokyoCorporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 Tokyo
Corporate Perl in Recruit, OpenSocial and Emoji‎ - YAPC::Asia 2009 Tokyo
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

PHP for Grown-ups

  • 1. Andrei Zmievski Chief Architect Outspark, Inc PHP for Grown-ups How 5.3, 6, and intl will change your life CONAPHP Brasil
  • 2.
  • 3.
  • 4. PHP 6 = PHP 5 + Unicode
  • 5. PHP 5 = PHP 6 -- Unicode
  • 6. Unicode = PHP 6 -- PHP 5
  • 7. What is PHP? Ha. Ha.
  • 8. What is Unicode? and why do I need?
  • 10. mojibake phenomenon of incorrect, unreadable characters shown when computer software fails to render a text correctly according to its associated character encoding
  • 13. Unicode provides a unique number for every character: no matter what the platform, no matter what the program, no matter what the language.
  • 14. unicode standard Developed by the Unicode Consortium Covers all major living scripts Version 5.0 has 99,000+ characters Capacity for 1 million+ characters Widely supported by standards & industry
  • 15. generative Composition can create “new” characters Base + non-spacing (combining) character(s) A + ˚ = Å U+0041 + U+030A = U+00C5 a + ˆ + . = ậ U+0061 + U+0302 + U+0323 = U+1EAD a + ̢ + ̌ = ǎ̢ U+0061 + U+0322 + U+030C = ?
  • 16. unicode != i18n Unicode simplifies development Unicode does not fix all internationalization problems
  • 17. definitions Internationalization I18n To design and develop an application: ✓ without built-in cultural assumptions ✓ that is efficient to localize Localization L10n To tailor an application to meet the needs of a particular region, market, or culture
  • 18. localized data date/time formats numbers, currency sorting and more
  • 19. locale data I18N and L10N rely on consistent and correct locale data Problem with POSIX locales: not always consistent or correct
  • 20. CLDR Hosted by Unicode Consortium Goals: Common, necessary software locale data for all world languages Collect and maintain locale data XML format for effective interchange Freely available Latest release: July 2008 (CLDR 1.6) 374 locales, with 137 languages and 140 territories
  • 21. PHP 6
  • 22. unicode support Everywhere: engine, extensions, API Native and complete Uses industry-standard ICU library
  • 23. sample Grab first 5 titles from Reuters China feed, clean up, and send out as JSON $xml = simplexml_load_file( 'http://feeds.feedburner.com/reuters/CNTbusinessNews/'); $titles = array(); $i = 0; foreach ($xml->channel->item as $item) {     // each title looks like this:     $title = preg_replace('!p{Ps}.*p{Pe}s*!', '', $item->title);     $titles[] = $title;     if (++$i == 5) break; } echo json_encode($titles);
  • 24. string types Unicode text default for literals, etc Binary bytes everything ∉ Unicode type
  • 25. string types internal processing: Unicode interface to outside world: binary
  • 26. Conversions streams Dataflow stream-specific encodings PHP Unicode strings Web runtime encoding Web binary “HTTP input encoding” HTTP output encoding strings script encoding filesystem encoding scripts filesystem
  • 27. strings String literals are Unicode $str = quot;Hello, world!quot;; // Unicode string echo strlen($str); // result is 13 $jp = quot; quot;; // Unicode string echo strlen($jp); // result is 7
  • 28. strings String offsets work on code points $str = quot; quot;; // 2 code points echo $str[1]; // result is $str[0] = ' '; full string is now //
  • 29. identifiers Unicode identifiers are allowed class {    function ᓱᓴᓐ ᐊᒡᓗᒃᑲᖅ { ... }    function !வா$ கேனச) { ... } function འquot;ག་%ལ། { ... } } $ = array(); $ [‘‫ = ]’ַרעְיולּוחַ ׁשָנָה‬new ();
  • 30. functions Functions understand Unicode text strtoupper() and friends do proper case mapping $str = strtoupper(quot;fußballquot;); // result is FUSSBALL $str = strtolower(quot;ΣΕΛΛΆΣquot;); // result is σελλάς strip_tags() works on complex text $str = strip_tags(quot; <span>είναι</span> quot;); strrev() preserves combining sequences $u = quot;Vieu0302u0323t Namquot;; // Việt Nam $str = strrev($u); // result is maN tệiV, // not maN ṭ̂eiV
  • 31. streams Built-in support for converting between Unicode strings and other encodings on the fly Reading from a UTF-8 text file: $fp = fopen('somefile.txt', 'rt');  $str = fread($fp, 100); // returns 100 Unicode characters  Writing to a UTF-8 text file: $fp = fopen('somefile.txt', 'wt');  fwrite($fp, $uni); // writes out data in UTF-8 encoding 
  • 32. streams Default encoding: stream_default_encoding('Shift-JIS'); $data = file_get_contents('somefile.txt', FILE_TEXT); // ... work on $data ... file_put_contents('somefile.txt', $data, FILE_TEXT); Custom contexts: $ctx = stream_context_create(NULL,                 array('encoding' => 'big5')); $data = file_get_contents('somefile.txt', FILE_TEXT, $ctx);  // ... work on $data ... file_put_contents('somefile.txt', $data, FILE_TEXT, $ctx);
  • 33. text iterator Use it when iterating over text in a linear fashion (instead of [] operator) Iteration over code points, characters, graphemes, words, lines, and sentences forward and backward Also provides ICU’s boundary analysis API
  • 34. text iterator Iterate over characters $text = quot;naiu308vequot;; // rendered as naïve foreach (new TextIterator($text, TextIterator::CHARACTER) as $u) { var_inspect($u); } Result unicode(1) quot;nquot; { 006e } unicode(1) quot;aquot; { 0061 } unicode(2) quot;ïquot; { 0069 0308 } unicode(1) quot;vquot; { 0076 } unicode(1) quot;equot; { 0065 }
  • 35. text iterator Iterate over words in reverse order $text = quot;Pouvez-vous me dire quelle heure il est ? Merci.quot;; foreach (new ReverseTextIterator($text, TextIterator::WORD) as $u) {     if ($u != quot; quot;) echo($u),quot;nquot;; } Result . Merci ? est il heure quelle dire me vous - Pouvez
  • 36. text iterator Truncate text at a word boundary $it = new TextIterator($text, TextIterator::WORD); $offset = $it->preceding(40); echo substr($text, 0, $offset), quot;...nquot;; Get the last 2 sentences of the text $it = new TextIterator($text, TextIterator::SENTENCE); $it->last(); $offset = $it->previous(2); echo substr($text, $offset); Get all the pieces delimited by boundaries $it = new TextIterator($text, TextIterator::WORD); $words = $it->getAll();
  • 37. text transforms Powerful and flexible way to process Unicode text script-to-script conversions normalization case mappings and full-/halfwidth conversions accent removal and more Allows chained transforms [:Latin:]; NFKD; Lower; Latin-Katakana;
  • 38. transliteration $names = quot; ,  ,  ,  ,  Горбачев, Михаил Козырев, Андрей Καφετζόπουλος, Θεόφιλος Θεοδωράτου, Ελένη quot;; $r = strtotitle(str_transliterate($names, quot;Anyquot;, quot;Latinquot;)); Gim, Gugsam Gim, Myeonghyi Takeda, Masayuki Oohara, Manabu Gorbačev, Mihail Kozyrev, Andrej Kaphetzópoulos, Theóphilos Theodōrátou, Elénē
  • 39. transliteration Here’s how to get (a fairly reliable) Japanese pronunciation of your name $k = str_transliterate('Britney Spears', 'Latin', 'Katakana'); echo($k),quot;nquot;; $l = strtotitle(str_transliterate($k, 'Katakana', 'Latin')); echo($l),quot;nquot;; Buritenei Supearusu
  • 40. other things APC bundled PCRE default regex engine “taint” mode traits a couple of syntactic sugar treats 64-bit integer type general cleanup
  • 42. features Locales Collation Number and Currency Formatters Date and Time Formatters Time Zones Calendars Message Formatter Choice Formatter Resource Handler Normalization
  • 43. versioning Works under PHP 5 and 6 Uses native strings in PHP 6 Requires UTF-8 strings in PHP 5 Can use mbstring, iconv
  • 45. comparing strings compare($str1, $str2) = -1,0,1 $coll = new Collator(quot;fr_CAquot;); if ($coll->compare(quot;côtequot;, quot;cotéquot;) < 0) {     echo quot;lessnquot;; } else {     echo quot;greaternquot;; } côte < coté
  • 46. sorting strings sort($array, $flags) asort($array, $flags) sortWithSortKeys($array) $strings = array(         quot;cotequot;, quot;côtequot;, quot;Côtequot;, quot;cotéquot;,         quot;Cotéquot;, quot;côtéquot;, quot;Côtéquot;, quot;coterquot;); $coll = new Collator(quot;fr_CAquot;); $coll->sort($strings); cote côte Côte coté Coté côté Côté coter
  • 49. what it is allows formatting numbers as strings according to the localized format or given pattern or set of rules and parsing strings into numbers according to these patterns replacement for number_format()
  • 50. formatter styles 123456.789 in en_US NumberFormatter::PATTERN_DECIMAL 123456.79 (with ##.##) NumberFormatter::DECIMAL 123456.789 NumberFormatter::CURRENCY $123,456.79 NumberFormatter::PERCENT 12,345,679%
  • 51. formatter styles 123456.789 in en_US NumberFormatter::SCIENTIFIC 1.23456789E5 NumberFormatter::SPELLOUT one hundred and twenty-three thousand, four hundred and fifty-six point seven eight nine NumberFormatter::ORDINAL 123,457th NumberFormatter::DURATION 34:17:37
  • 52. formatting format($number [, $type]) $fmt = new NumberFormatter(‘en_US’, NumberFormatter::DECIMAL); $fmt->format(1234); // result is 1,234 $fmt = new NumberFormatter(‘de_CH’, NumberFormatter::DECIMAL); $fmt->format(1234); // result is 1'234
  • 54. what it is produces concatenated messages in a language-neutral way operates on patterns, which contain subformats
  • 55. what it is Need to get: Today is November 21, 2007. Normal PHP way: date(‘F d, Y’) MessageFormat would use pattern: Today is {0,date}. arg: array(time())
  • 56. formatting format($args) $pattern = “On {0,date} you have {1,number} meetings.”; $args = array(time(), 2); $fmt = new MessageFormatter(‘en_US’, $pattern); echo $fmt->format($args); // On November 22, 2007 you have 2 meetings.
  • 57. formatting Trying different locales $fr_pattern = quot;Aujourd''hui, {0,date,dd MMMM}, il y a {1,number} personnes sur {3}.quot;; $fr_args = array(time(), 6579844000.0, 3, quot;la Terrequot;); $msg = new MessageFormatter('fr_FR', $fr_pattern); echo $msg->format($fr_args); // Aujourd'hui, 22 novembre, il y a 6 579 844 000 personnes sur la Terre.
  • 59. namespaces designed to solve scoping problems perhaps the most discussed issue ever on the internals list complex topic - still under work
  • 61. lambdas and closures anonymous functions scope capture should be familiar to JS users $lambda = function () {  echo quot;Hello World!nquot;; }; $lambda();
  • 62. lambdas and closures more complex example function getAdder($x) {     return function ($y) use ($x) {         return $x + $y;     }; } $adder = getAdder(10); print_r( array_map( $adder, array(1, 2, 3) ) ); Array ( [0] => 11 [1] => 12 [2] => 13 )
  • 63. phar PHp ARchive PharData = PDO for tar and zip files encapsulated applications
  • 65. php archives access file in archive  include 'phar:///path/to/myphar.phar/file.php'; host an entire application // create app archive $phar = new Phar('myphar.phar'); $phar['cli.php']   = '<?php echo quot;Hello CLI Worldquot;; ?>'; $phar['index.php'] = '<?php echo quot;Hello Web Worldquot;; ?>'; $phar->setDefaultStub('cli.php', 'index.php');
  • 67. other garbage collection NOWDOC limited GOTO ternary shortcut ?: numerous fixes, additions, and cleanups
  • 68.