亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP select first sentence from each part of split text and display them together
P粉032977207
P粉032977207 2023-07-17 18:42:29
0
1
521


Can someone please help me add some code and help me complete this task? I need help choosing the first sentence in each set of five sentences. Then place the first sentence of each group into a paragraph. Finally display them together.

I've done most of the work on this complex task: opening the file using PHP, storing the contents in an array, splitting the array into sentences, and grouping the sentences into groups of five sentences each.



code show as below

//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


P粉032977207
P粉032977207

reply all(1)
P粉132730839

例如,您可以在 array_chunk 中省略最后一個(gè)參數(shù)以不保留鍵,并使用 array_map 返回從 array_chunk 返回的數(shù)組的第一個(gè)條目。

然后使用 implode 和一個(gè)空格。

以下使用箭頭函數(shù)的示例:

$result = preg_split('/(?<=[.?!;:])\s+/', $text, -1, PREG_SPLIT_NO_EMPTY); $result = implode(" ", array_map( fn($arr) => $arr[0],
    array_chunk($result, 5))
);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template