/ Published in: PHP
URL: http://www.barattalo.it/2009/11/24/truncate-string-preserving-some-words-in-php/
This function truncates text preserving the keyords specified, usefull for search results that should highlight found words.
Expand |
Embed | Plain Text
//$h = text //$n = keywords to find separated by space //$w = words near keywords to keep function truncatePreserveWords ($h,$n,$w=5,$tag='b') { for ($j=0;$j<count($b);$j++) $c[$j]=false; for ($i=0;$i<count($b);$i++) for ($k=0;$k<count($n);$k++) } $o = ""; // reassembly words to keep for ($j=0;$j<count($b);$j++) if ($c[$j]) $o.=" ".$b[$j]; else $o.="."; }
You need to login to post a comment.
