title: How to limit string to some character in php
body: <p>I have a php code which displays description of each post in main page(www.kushaku.com):
  Below is the code which displays description: </p>
  
  <pre><code>   &lt;p class="shortdesc1"&gt;
       &lt;?php the_content(); ?&gt; 
     &lt;/p&gt;
  </code></pre>
  
  <p>I am tryin to limit the description part of main page to some characters, say 180 characters, and after that display '...'</p>
  
  <p>I tried below code:</p>
  
  <pre><code>  function string_limit_words($string, $word_limit)
   {
     $words = explode(' ', $string, ($word_limit + 1));
     if(count($words) &gt; $word_limit) {
     array_pop($words);
     //add a ... at last article when more than limit word count
     echo implode(' ', $words)."..."; } else {
     //otherwise
     echo implode(' ', $words); }
   }
  
  
  
  
   &lt;?php
     $excerpt = the_content();
     echo string_limit_words($excerpt,25);
   ?&gt;
  </code></pre>
  
  <p>but it is still showing full content.
  If i print count($words), it is showing '1', 
  if i take strlen of $string, it gives me output as '0'.
  If i use count_chars() it gives me output as '0'.</p>
  
  <p>Please suggest any way to achieve my objective.</p>
  
  <p>Thanks in Advance,
  Vivek</p>