函式名:IntlBreakIterator::current()
適用版本:PHP 5 >= 5.5.0, PHP 7, PHP 8
用法:這個函式用於獲取當前迭代器位置的斷句。
示例:
$text = "Hello. How are you?";
// 建立一個斷句迭代器
$iterator = IntlBreakIterator::createSentenceInstance();
$iterator->setText($text);
// 獲取第一個斷句的位置
$iterator->first();
// 獲取當前迭代器位置的斷句
$currentSentence = $iterator->current();
echo $currentSentence; // 輸出:Hello.
// 移動到下一個斷句
$iterator->next();
// 獲取當前迭代器位置的斷句
$currentSentence = $iterator->current();
echo $currentSentence; // 輸出:How are you?
在上面的示例中,我們首先建立了一個斷句迭代器,並將待分析的文字設定為迭代器的文字。然後,使用first()
方法將迭代器的位置設定為第一個斷句,並使用current()
方法獲取當前斷句。接著,使用next()
方法將迭代器的位置移動到下一個斷句,並再次使用current()
方法獲取當前斷句。
請注意,這個函式需要安裝Intl擴充套件才能使用。