The IntlBreakIterator class

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

简介

A "break iterator" is an ICU object that exposes methods for locating boundaries in text (e.g. word or sentence boundaries). The PHP IntlBreakIterator serves as the base class for all types of ICU break iterators. Where extra functionality is available, the intl extension may expose the ICU break iterator with suitable subclasses, such as IntlRuleBasedBreakIterator or IntlCodePointBreakIterator.

This class implements Traversable. Traversing an IntlBreakIterator yields non-negative integer values representing the successive locations of the text boundaries, expressed as UTF-8 code units (byte) counts, taken from the beginning of the text (which has the location 0). The keys yielded by the iterator simply form the sequence of natural numbers {0, 1, 2, ...}.

类摘要

IntlBreakIterator implements Traversable {
/* 常量 */
const int DONE = -1 ;
const int WORD_NONE = 0 ;
const int WORD_NONE_LIMIT = 100 ;
const int WORD_NUMBER = 100 ;
const int WORD_NUMBER_LIMIT = 200 ;
const int WORD_LETTER = 200 ;
const int WORD_LETTER_LIMIT = 300 ;
const int WORD_KANA = 300 ;
const int WORD_KANA_LIMIT = 400 ;
const int WORD_IDEO = 400 ;
const int WORD_IDEO_LIMIT = 500 ;
const int LINE_SOFT = 0 ;
const int LINE_SOFT_LIMIT = 100 ;
const int LINE_HARD = 100 ;
const int LINE_HARD_LIMIT = 200 ;
const int SENTENCE_TERM = 0 ;
const int SENTENCE_TERM_LIMIT = 100 ;
const int SENTENCE_SEP = 100 ;
const int SENTENCE_SEP_LIMIT = 200 ;
/* 方法 */
private __construct ( )
public static createCharacterInstance ( string|null $locale = null ) : IntlBreakIterator|null
public static createLineInstance ( string|null $locale = null ) : IntlBreakIterator|null
public static createSentenceInstance ( string|null $locale = null ) : IntlBreakIterator|null
public static createTitleInstance ( string|null $locale = null ) : IntlBreakIterator|null
public static createWordInstance ( string|null $locale = null ) : IntlBreakIterator|null
public current ( ) : int
public first ( ) : int
public following ( int $offset ) : int
public getErrorCode ( ) : int
intl_get_error_code ( ) : int
public getErrorMessage ( ) : string|false
intl_get_error_message ( ) : string
public getLocale ( int $type ) : string
public getPartsIterator ( string $type = IntlPartsIterator::KEY_SEQUENTIAL ) : IntlPartsIterator
public getText ( ) : string|null
public isBoundary ( int $offset ) : bool
public last ( ) : int
public next ( int|null $offset = null ) : int
public preceding ( int $offset ) : int
public previous ( ) : int
public setText ( string $text ) : bool|null
}

预定义常量

IntlBreakIterator::DONE

IntlBreakIterator::WORD_NONE

IntlBreakIterator::WORD_NONE_LIMIT

IntlBreakIterator::WORD_NUMBER

IntlBreakIterator::WORD_NUMBER_LIMIT

IntlBreakIterator::WORD_LETTER

IntlBreakIterator::WORD_LETTER_LIMIT

IntlBreakIterator::WORD_KANA

IntlBreakIterator::WORD_KANA_LIMIT

IntlBreakIterator::WORD_IDEO

IntlBreakIterator::WORD_IDEO_LIMIT

IntlBreakIterator::LINE_SOFT

IntlBreakIterator::LINE_SOFT_LIMIT

IntlBreakIterator::LINE_HARD

IntlBreakIterator::LINE_HARD_LIMIT

IntlBreakIterator::SENTENCE_TERM

IntlBreakIterator::SENTENCE_TERM_LIMIT

IntlBreakIterator::SENTENCE_SEP

IntlBreakIterator::SENTENCE_SEP_LIMIT

Table of Contents

User Contributed Notes

SenseException 04-Dec-2013 08:53
Since there is no excample for the usage of the IntlBreakIterator yet, I made a small one:

<?php

$text
= "Si contano i danni. Un morto a Roma, un treno ".
"deragliato e quattro feriti a Foggia, strade chiuse in tutto ".
"il sud, allagamenti e danni sulla costa ionica. A Pescara, ".
"1.500 sfollati per l'esondazione del Fosso Vallelunga. ".
"Dall'inizio dell'anno l'agricoltura ha subito un miliardo ".
"di euro di danni.";

$locale = 'it_IT';

$i = IntlBreakIterator::createSentenceInstance($locale);
$i->setText($text);

foreach(
$i->getPartsIterator() as $sentence) {
    echo
$sentence . PHP_EOL . '----- next -----' PHP_EOL;
}

?>

Result:

Si contano i danni.
----- next -----
Un morto a Roma, un treno deragliato e quattro feriti a Foggia, strade chiuse in tutto il sud, allagamenti e danni sulla costa ionica.
----- next -----
A Pescara, 1.500 sfollati per l'esondazione del Fosso Vallelunga.
----- next -----
Dall'inizio dell'anno l'agricoltura ha subito un miliardo di euro di danni.
----- next -----
PHP8中文手册 站长在线 整理 版权归PHP文档组所有