There is a .txt file. Not formatted "as is" downloaded from the network. Let's say this is a book. It is necessary: ​​Split this file into sentences (from point to point), BUT, so that sentences including characters were no longer than 140 characters.

For example, this sentence will fit remarkably in one hundred and forty characters and will fit this small but interesting task, something like two times.

Sentences that exceed 140 characters (including a dot at the end) - the script discards. Prints out line by line view: sentence sentence sentence sentence

I know that there is a function substr. she needs 3 arguments. The first is the line itself, the second from which character to start to trim the text (the numbering starts from zero), and the third is how many characters to trim. But can it really do something else? because substr I did not work.

    1 answer 1

    $sentences = explode('.', $text); $sentences = array_filter($sentences, function($s) { $s = trim($s); return strlen($s) > 0 && strlen($s) < 140; }); 

    ps on big data will surely die
    pps where did I get the feeling that this job has a specific customer?

    • No, there is no customer)) this is for personal use (twitter). Thank you for your decision! Now, on Yii, I nakuralesil slightly. THANK! - sleepn0w