Have a list of words - need a program to delete words longer than 11 letters

Discussion in 'Programming' started by Ashkan, Jul 11, 2007.

  1. #1
    I have a list of 200,000 words in a text file and am looking for a program to run through and delete the words that are longer than 11 letters. It's pretty simple but is there one out there?
     
    Ashkan, Jul 11, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    
    
    $file = fopen('textfile','r');
    while($tot = fread($file,125647)){$content .= $tot;}
    fclose($file);
    
    $lines = explode($content,"\n");
    
    $new_file = fopen('newtextfile','w');
    
    foreach($lines as $line){
        if(strlen($line) <= 11){ fwrite($new_file,$line."\n");}
    }
    
    fclose($new_file);
    
    PHP:
    Peace,
     
    Barti1987, Jul 11, 2007 IP
  3. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #3
    Use a regular expression find/replace on dreamweaver, textpad or other programs supporting regular expressions

    find: "^.{12,}$"
    change all occurences to : "" or "whatever you want"

    dont type the quotes
     
    nabil_kadimi, Jul 11, 2007 IP