PHP Conference Japan 2024

La clase IntlCodePointBreakIterator

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

Introducción

Este iterador de ruptura identifica los límites entre puntos de código de UTF-8.

Sinopsis de la Clase

class IntlCodePointBreakIterator extends IntlBreakIterator implements Traversable {
/* Constantes */
const integer DONE = -1;
const integer WORD_NONE = 0;
const integer WORD_NUMBER = 100;
const integer WORD_LETTER = 200;
const integer WORD_KANA = 300;
const integer WORD_IDEO = 400;
const integer LINE_SOFT = 0;
const integer LINE_HARD = 100;
const integer SENTENCE_SEP = 100;
/* Métodos */
public getLastCodePoint(): ReturnType
/* Métodos heredados */
public static IntlBreakIterator::createCharacterInstance(string $"locale" = ?): ReturnType
public static IntlBreakIterator::createCodePointInstance(): ReturnType
public static IntlBreakIterator::createLineInstance(string $"locale" = ?): ReturnType
public static IntlBreakIterator::createSentenceInstance(string $"locale" = ?): ReturnType
public static IntlBreakIterator::createTitleInstance(string $"locale" = ?): ReturnType
public static IntlBreakIterator::createWordInstance(string $"locale" = ?): ReturnType
public IntlBreakIterator::current(): ReturnType
public IntlBreakIterator::first(): ReturnType
public IntlBreakIterator::following(string $"offset"): ReturnType
public IntlBreakIterator::getErrorCode(): ReturnType
intl_get_error_code(): ReturnType
intl_get_error_message(): ReturnType
public IntlBreakIterator::getLocale(string $"locale_type"): ReturnType
public IntlBreakIterator::getPartsIterator(string $"key_type" = ?): ReturnType
public IntlBreakIterator::getText(): ReturnType
public IntlBreakIterator::isBoundary(string $"offset"): ReturnType
public IntlBreakIterator::last(): ReturnType
public IntlBreakIterator::next(string $"offset" = ?): ReturnType
public IntlBreakIterator::preceding(string $"offset"): ReturnType
public IntlBreakIterator::previous(): ReturnType
public IntlBreakIterator::setText(string $"text"): ReturnType
}

Tabla de contenidos

add a note

User Contributed Notes 1 note

up
0
Matt Kynx
2 years ago
An example of using this to find all the code points in a string that cannot be transliterated to Latin-ASCII:

<?php

$string
= "Народm, Intl gurus get paid €10000/hr 😁";

$latinAscii = Transliterator::create('NFC; Any-Latin; Latin-ASCII;');
$transliterated = $latinAscii->transliterate($string);

$codePoints = IntlBreakIterator::createCodePointInstance();
$codePoints->setText($transliterated);

foreach (
$codePoints->getPartsIterator() as $char) {
$ord = IntlChar::ord($char);
if (
255 < $ord) {
echo
IntlChar::charName($ord) . "\n";
}
}
?>

Outputs:
EURO SIGN
GRINNING FACE WITH SMILING EYES
To Top