View Full Version : Remove All Lines Less Than 3 Words Longs
young_coder
09-09-2010, 07:13 PM
Dear all,
I want to remove all lines less than 3 words longs so I can stuff the rest into a db.
Can somebody help me?
Thank you in advance
djr33
09-09-2010, 11:04 PM
What is a "line"? And what is a "word"?
If you split at line breaks (\r\n), then split each line at spaces, you can count to see which lines are too short.
<?php
$text = explode("\r\n",$text); //use \n or \r if this doesn't work
foreach ($text as $tk=>$tv) {
$line = explode(' ',$tv);
if (count($line)<=3) { unset($text[$tk]; }
}
$text = implode("\r\n",$text);
//echo $text;
Remember that's a very simple analysis so it may not accurately handle real language data.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.