Can someone please add some code and help me complete the assignment ? I need help selecting first sentence in a group of sentences of five. Then put these first sentences from each group into one paragraph. Then display them together.
I have already completed major part of this complex task: Using PHP I open file, put contents in array, divide the array into sentences, group the sentences in groups of five.
The code is here:
//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
You could for example omit the last parameter in array_chunk to not keep the keys, and then use array_map returning the first entry of the array returned from array chunk.
Then use implode with a space.
Example using an arrow function: