johnzuk / hunspellphp Goto Github PK
View Code? Open in Web Editor NEWHunspell PHP wrapper
License: MIT License
Hunspell PHP wrapper
License: MIT License
HunspellPHP/src/HunspellPHP/Hunspell.php
Line 128 in 7c936c3
The referenced line does not appear to work on my windows machine or my centOS7 server. The output from the command is empty. I've had to hack my version of this function to do this, and please don't mind the 'hackyness' as I'm not super fluent with the whole command line interactivity stuff.
Oh by the way I also added support for a dictionary file. The reasoning is that the site I'm using this for has lots of brand name stuff that comes up as misspellings so I wrote a script to weight every word on the site and created a hunspell dictionary file out of the big / common ones. It works well, though I didnt put a lot of thought into keeping the code neat and clean as I didn't really expect anyone to see this lol.
As to a run down of what I'm doing, is I'm loading the dictionary file into memory if it exists, Then I save it as a temp file with the $input var appended (not sure why anymore I did this a while back - however since I'm not providing the $Input var to the command line that must be related to the reason or is otherwise how hunspell is getting the $input). After that I create an empty temp file to dump the output of the shell command. After the command runs I get the output from the temp file, delete both files and return the output.
Do you approve of this? Do you want me to do a PR and clean it up or if you want to implement it your self that would be cool. I'd also be interested on your take as to why there is no output from the provided command. I think it has something to do with the path vars and my environment or something.
Obviously the dictionary file support would have to be added to the actual options rather than hard coded.
` $dictionary_file = $_SERVER["DOCUMENT_ROOT"] . ".dictionary.txt";
if(file_exists($dictionary_file)) {
$custom_dictionary = file_get_contents($dictionary_file);
} else {
$custom_dictionary = "";
}
$tmp = tempnam(sys_get_temp_dir(), 'hunspell');
file_put_contents($tmp, $custom_dictionary . "\n" . $input);
$tmp2 = tempnam(sys_get_temp_dir(), 'hunspell');
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$cmd = 'C:\\hunspell\\bin\\hunspell.exe -a -d en_US ' . $tmp . " > " . $tmp2;
} else {
$cmd = 'hunspell -a -d en_US ' . $tmp . " > " . $tmp2;
}
shell_exec($cmd);
unlink($tmp);
$out = file_get_contents($tmp2);
unlink($tmp2);
$out = explode("\n", trim($out));
array_shift($out);
$out = implode(" ", $out);
return $out;`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.