Count Grammar and Spelling Error

I like this tool very much and i have intregated it into my website also. I just want to know that can we count the grammatical errors and spelling errors of what it is showing.

This is not supported out of the box, you’ll need to modify the Javascript code to do this.

first of all i would like to thank you for your response. can you please help me out in making changes in javascript and i also don’t know what to change and where to change.
thanks in advance.

please Sir, help me out in making changes in Javascript. Can you please send me updated javascript code so that it can also counts errors.
Thanks inAdvance

If you have integrated LT on your website, why don’t you code the number of errors found in PHP?

//first we load the outputted XML file
$xml=simplexml_load_file("$outputfile") or die("Error: Cannot create object");

//now we get the contents of that file
$grammarerrors = file_get_contents($outputfile);
//now we count the number of times FROMX appears in that file
$grammarerrorscount = substr_count($grammarerrors, 'fromx');

//now, let's print the number of errors
if ($grammarerrorscount==0){
          echo "<h3>Perfect!</h3>";
          echo "<div>Not a single grammar mistake was found!</div>";
  }
  elseif ($grammarerrorscount==1){
          echo "<h3>Only one grammar mistake!</h3>";
  }
  else {
          echo "<h3>You seem to have made $grammarerrorscount grammar mistakes!</h3>";
  }

the same problem here I want to get the count of the grammar and spelling errors instead. Can you help me for the solution?

Hi asmith, I already tried your code in my php page but somehow the output of the java script is not in xml form, could you please elaborate more on the script how to get the xml result? I use the java cript in Integration On Websites - LanguageTool Wiki

thx in advance

My PHP code does not alter javascript or LT. It takes the XML file which is generated by LT when a user processes an input, it counts the number of errors in that XML file, and it outputs the result in PHP.

Do you know exactly where is LT put the XML file more precisely so I can pinpoint it to input it in the PHP code

Actually I’ve just noticed that the XML file format has been deprecated, so I’m going to have to make my own changes:

http://wiki.languagetool.org/command-line-options

Having said that, here’s a simple PHP command-line integration code which specifies where to put the input file and the outputted XML file:

$inputfilename = md5($input);
$inputfile = "input-directory/$inputfilename" . '.txt';
$outputfile = "output-directory/$inputfilename" . '.xml';

$cmd = "java -jar languagetool/languagetool-commandline.jar -l en -c UTF-8 -d --api $inputfile > $outputfile 2>&1";
1 Like

Thank you!
For those who need an answer to workaround counting grammatical error from many text file in a folder here is the link