我有两个脚本。这两个脚本位于同一服务器上的同一文件夹中。
脚本1:
<?php
$text = "Is this not working? Why, yes it is.";
$locale = 'en_US';
$i = IntlBreakIterator::createSentenceInstance($locale);
$i->setText($text);
foreach($i->getPartsIterator() as $sentence) {
echo $sentence . PHP_EOL . '----- next -----' . PHP_EOL;
}
?>
脚本2:
... bunch of other code ...
$doc = file_get_contents("file.txt");
$locale = 'en_US';
$i = IntlBreakIterator::createSentenceInstance($locale);
$i->setText($doc);
foreach($i->getPartsIterator() as $sentence) {
echo $sentence . PHP_EOL . '----- next -----' . PHP_EOL;
}
... bunch of other code ...
脚本1将按预期执行,并具有所需的输出且没有错误。脚本2无法执行,PHP不断抛出错误PHP Fatal error: Uncaught Error: Class 'IntlBreakIterator' not found
这是怎么回事?