/** * Prepares results from search for display * * @param string The source string * @param int Number of chars to trim * @param string The searchword to select around * @return string */ static function prepareSearchContent($text, $length = 200, $searchword_arr) { // strips tags won't remove the actual jscript $text = preg_replace("'<script[^>]*>.*?</script>'si", "", $text); $text = preg_replace('/{.+?}/', '', $text); //$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text ); // replace line breaking tags with whitespace $text = preg_replace("'<(br[^/>]*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si", ' ', $text); if (($wordpos = @JString::strpos($text, ' ', $length)) !== false) { $start_part = JString::substr($text, 0, $wordpos) . ' ...'; } else { $start_part = JString::substr($text, 0, $length); } $parts = array(); foreach ($searchword_arr as $searchword) { $part = FLEXIadvsearchHelper::_smartSubstr(strip_tags($text), $length, $searchword, $pos); if ($pos !== false) { $parts[$searchword] = $part; $positions[$pos] = $searchword; } } if (count($parts)) { $oparts = array(); ksort($positions); foreach ($positions as $pos => $searchword) { $oparts[$searchword] = $parts[$searchword]; } return $oparts; } else { return array('' => $start_part); } }