title: Limit HTML Text to 500 characters
body: <p>I have the following code that limits a html text to 500 characters:</p>
  
  <pre><code>if (strlen($text)&gt;500) {
     $message = substr($text, 0, 500);
     echo $message;
  }
  else {
     echo $text;
  }
  </code></pre>
  
  <p>The problem is that sometimes the code cuts in the middle of the tag, so the output is:</p>
  
  <pre><code>...............................................Some text &lt;a hre
  </code></pre>
  
  <p>How can I fix this?</p>