Results 1 to 2 of 2

Thread: Remove All Lines Less Than 3 Words Longs

  1. #1
    Join Date
    Feb 2010
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Remove All Lines Less Than 3 Words Longs

    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

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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 Code:
    <?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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •