title: Get word count for first line in doc/docx/pdf file
body: <p>For my task, I have to get the total word count of an uploaded .doc, .docx or .pdf file. Then, I have to find the word count in the first line of the document and remove it from the total (since it is probably going to be the title).</p>
  
  <p>I am using <a href="https://github.com/joeblurton/doccounter" rel="nofollow noreferrer">doccounter</a> to find the total word count of a document as such:</p>
  
  <pre><code>include "class.doccounter.php";
  
  $doc = new DocCounter();
  $doc-&gt;setFile("file.ext");
  
  print_r($doc-&gt;getInfo());
  echo ($doc-&gt;getInfo()-&gt;wordCount);
  </code></pre>
  
  <p>All that is left is to find the word count of the first line of the uploaded file. Any solutions including additional libraries or native implementations are welcome! Thank you!</p>
  
  <p>Edit - Solution (Credit to <a href="https://stackoverflow.com/users/5300921/rustyjim">Rustyjim</a>):</p>
  
  <pre><code>$doc = new DocCounter();
  $doc-&gt;setFile("file.pdf");
  $text = $doc-&gt;getInfo()-&gt;toText; // Edited doccounter to return text as string
  $array = explode("\n", $text); // every cell contains a new line of the text
  echo $array[0]; // First line
  </code></pre>