title: limit string to first 5 words or first 42 characters in PHP
body: <p>If I have a string in PHP that is obnoxiously long string in PHP and I want to shorten it and then append something to it.</p>
  
  <p>I want to shorten it to the first 6 words or 42 characters, whatever is shorter and then append a '...' to it if it was shortened.</p>
  
  <p>The only case it would not be shortened and the '...' not added would be if it was originally less than 6 words or 42 characters.</p>
  
  <p>How can I do this in PHP?</p>
  
  <p>Logically, I would think I would split the string by white-space and then add each thing before the white-space in an array and take only the first 6 elements out of that array and write them to a new string.</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>str_1 = 'The quick brown fox jumped over the lazy dog';
  $words = explode(" ", $str_1);
  $counter = 0;
  str_2 = '';
  foreach($words as $word){
      if($counter &lt; 5){
          //append $words[counter] to str_2;
          counter++;
      }
      else{
          break;
      }
  }
  </code></pre>
  
  <p>I don't know how to do the rest for character count or comparison or appending.</p>
  
  <p>Does anyone have any ideas?</p>