/ Published in: PHP
This function truncates text preserving the keyords specified, usefull for search results that should highlight found words.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//$h = text //$n = keywords to find separated by space //$w = words near keywords to keep function truncatePreserveWords ($h,$n,$w=5,$tag='b') { } $o = ""; // reassembly words to keep }
URL: http://www.barattalo.it/2009/11/24/truncate-string-preserving-some-words-in-php/