title: How to generate excerpt with most searched words in PHP?
body: <p>Here is an excerpt function:</p>
  
  <pre><code>    function excerpt($text, $phrase, $radius = 100, $ending = "...") {
  270             if (empty($text) or empty($phrase)) {
  271                 return $this-&gt;truncate($text, $radius * 2, $ending);
  272             }
  273     
  274             $phraseLen = strlen($phrase);
  275             if ($radius &lt; $phraseLen) {
  276                 $radius = $phraseLen;
  277             }
  278     
  279             $pos = strpos(strtolower($text), strtolower($phrase));
  280     
  281             $startPos = 0;
  282             if ($pos &gt; $radius) {
  283                 $startPos = $pos - $radius;
  284             }
  285     
  286             $textLen = strlen($text);
  287     
  288             $endPos = $pos + $phraseLen + $radius;
  289             if ($endPos &gt;= $textLen) {
  290                 $endPos = $textLen;
  291             }
  292     
  293             $excerpt = substr($text, $startPos, $endPos - $startPos);
  294             if ($startPos != 0) {
  295                 $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen);
  296             }
  297     
  298             if ($endPos != $textLen) {
  299                 $excerpt = substr_replace($excerpt, $ending, -$phraseLen);
  300             }
  301     
  302             return $excerpt;
  303         }
  </code></pre>
  
  <p>Its drawback is that it doesn't try to match as many searched words as possible,which only matches once by default.</p>
  
  <p>How to implement the desired one?</p>