1--TEST-- 2IntlCodepointBreakIterator::getLastCodePoint(): basic test 3--EXTENSIONS-- 4intl 5--FILE-- 6<?php 7ini_set("intl.error_level", E_WARNING); 8ini_set("intl.default_locale", "pt_PT"); 9 10$text = 'ตัวอย่างข้อความ'; 11 12$codepoint_it = IntlBreakIterator::createCodePointInstance(); 13$codepoint_it->setText($text); 14 15var_dump($codepoint_it->getLastCodePoint()); 16//first() and last() don't read codepoint and set the last code point var to -1 17//The pointer is after the last read codepoint if moving forward and 18//before the last read codepoint is moving backwards 19$p = $codepoint_it->first(); 20while ($p != IntlBreakIterator::DONE) { 21 $c = $codepoint_it->getLastCodePoint(); 22 if ($c > 0) 23 var_dump(sprintf('U+%04X', $codepoint_it->getLastCodePoint())); 24 else 25 var_dump($c); 26 //it's a post-increment operation as to the codepoint, i.e., it gives the codepoint 27 //starting at the initial position and only then moves the pointer forward 28 $p = $codepoint_it->next(); 29} 30 31echo "Now backwards\n"; 32$p = $codepoint_it->last(); 33while ($p != IntlBreakIterator::DONE) { 34 $c = $codepoint_it->getLastCodePoint(); 35 if ($c > 0) 36 var_dump(sprintf('U+%04X', $codepoint_it->getLastCodePoint())); 37 else 38 var_dump($c); 39 $p = $codepoint_it->previous(); 40} 41 42 43?> 44--EXPECT-- 45int(-1) 46int(-1) 47string(6) "U+0E15" 48string(6) "U+0E31" 49string(6) "U+0E27" 50string(6) "U+0E2D" 51string(6) "U+0E22" 52string(6) "U+0E48" 53string(6) "U+0E32" 54string(6) "U+0E07" 55string(6) "U+0E02" 56string(6) "U+0E49" 57string(6) "U+0E2D" 58string(6) "U+0E04" 59string(6) "U+0E27" 60string(6) "U+0E32" 61string(6) "U+0E21" 62Now backwards 63int(-1) 64string(6) "U+0E21" 65string(6) "U+0E32" 66string(6) "U+0E27" 67string(6) "U+0E04" 68string(6) "U+0E2D" 69string(6) "U+0E49" 70string(6) "U+0E02" 71string(6) "U+0E07" 72string(6) "U+0E32" 73string(6) "U+0E48" 74string(6) "U+0E22" 75string(6) "U+0E2D" 76string(6) "U+0E27" 77string(6) "U+0E31" 78string(6) "U+0E15" 79