title: Count lines in textarea including automatic line breaks
body: <p>I have a textarea</p>
  
  <pre><code>&lt;textarea id="text" name="text" rows="6"&gt;&lt;/textarea&gt;
  
  &lt;style&gt;
      #text { width: 30%; }
  &lt;/style&gt;
  </code></pre>
  
  <p>When submitting the form, I need to check if the input exceeded 6 rows. I have a JS code, which checks for scrollbar (scrollbar present = more than 6 lines = invalid input) which works perfectly. The tricky part is, how can validate the input with PHP in case of disabled JS?</p>
  
  <p>I tried something like this</p>
  
  <pre><code>public function overflowValidator($input, $maxLines, $cols) {
      $linebreakCount = substr_count($input, "\n");
      $overflow1 = ($linebreakCount &lt;= $maxLines);
      $overflow2 = (ceil(strlen($input) / $cols) &lt;= $maxLines);
      return $overflow1 &amp;&amp; $overflow2;
  }
  </code></pre>
  
  <p>The biggest problem is that the width of the textarea is dynamic (responsive design) so I can't easily tell how many letters fit into one line. I'm afraid this can't be solved but maybe there is a solution I'm not aware of...</p>