3v4l.org

run code in 500+ PHP versions simultaneously
<?php $fulltext = "-through the +use of the +tab +key"; $length = 4; function checkstring($fulltext,$length) { $words = preg_split('~\s~',$fulltext); $remains = []; foreach ($words as $word) { if (strpos($word, '-') === 0) { continue; } if (strpos($word, '+') === 0) { $word = substr($word, 1); } elseif (strlen($word) <= $length) { continue; } $remains[] = $word; } return trim(implode(' ', $remains)); } echo checkstring($fulltext, $length);

preferences:
24.2 ms | 474 KiB | 4 Q