Jump to content

Remove All Lines Less Than 3 Words Longs


young_coder

Recommended Posts

$text =<<<TEXT
line containing more than three words
less than
three words
on the previous two lines
TEXT;

$split = explode("\n", $text);
foreach($split as $key => $line) {
    if(str_word_count($line, 0) < 3) {
        unset($split[$key]);
    }
}
echo implode("\n", $split);

 

str_word_count

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.