Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove Non-Words

Posted on 2010-09-16
2
Medium Priority
?
284 Views
Last Modified: 2012-05-10
Hi,

I'm looking for a way to remove non-english dictionary words from a file that has 3 fields:

Example:

word      xxword      x      xa      worlds

I'm looking to output only dictionary words:

word      hello        worlds

I'm pretty sure this would be possible to accomplish by using a dictionary that comes with Unix by overlapping the two files and outputting matches and formatting.


IThank you
0
Comment
Question by:faithless1
2 Comments
 
LVL 8

Accepted Solution

by:
shanikawm earned 1800 total points
ID: 33699184
You can use php Pspell functions.

e.g.:

cat file.txt

penn pencil eraser
black bleu red
monitor key muose

php spell.php

pencil eraser
black red
monitor key

<?php
$pspell_link = pspell_new("en");
$lines=file('file.txt');
foreach ($lines as $line)
{
        $words=preg_split('/[ \s]+/',trim($line));
        foreach ($words as $word)
        {
                if(pspell_check($pspell_link,$word))
                {
                        echo $word,' ';
                }
        }
        echo "\n";
}
?> 

Open in new window

0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 33701333
See the notes here:
http://us.php.net/manual/en/pspell.installation.php

You can run this script to find out if you've got pSpell:
<?php phpinfo(); ?>

This search may have some good examples if you do not have the extension installed.
http://lmgtfy.com?q=PHP+spell+checking
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question