有人可以帮我添加一些代码并帮助我完成这个任务吗?我需要帮助选择每组五个句子中的第一句。然后将每组的第一句放入一个段落中。最后将它们一起显示出来。
我已经完成了这个复杂任务的大部分工作:使用PHP打开文件,将内容存储在数组中,将数组分割成句子,并将句子分组为每组五个句子。
代码如下
//Reading file contents
$text = file_get_contents( 'majmunskikompjuter.txt' );
echo $text;
//Divide the text into sentences
$result = preg_split('/(?<=[.?!;:])s+/', $text, -1, PREG_SPLIT_NO_EMPTY);
print_r($result);
//Divide the text into equal parts containing 5 sentences each
$input_array = $result;
print_r(array_chunk($input_array, 5, true));
//Select first sentence from each part of the divided text and display together ???? Need help
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号