Browse Source

function to highlight search terms in search.php

main
Simon Bowie 2 years ago
parent
commit
bdc1f1546a
2 changed files with 20 additions and 0 deletions
  1. +11
    -0
      site/public/search.php
  2. +9
    -0
      site/text_functions.php

+ 11
- 0
site/public/search.php View File

# @purpose: Searches the Solr index # @purpose: Searches the Solr index


include '../solr.php'; include '../solr.php';
include '../text_functions.php';


?> ?>




foreach($search_results as $result): foreach($search_results as $result):


$result = highlight_search_terms($result, $_POST["search"]);
?> ?>
Application ID: Application ID:


?> ?>


</div> </div>
<script>
let text = "<?php echo $_POST["search"]; ?>";
upperText = text.toUpperCase();
result = "<span style='color:green'>" + upperText + "</span>";
const collection = document.getElementsByClassName("search_term");
for (let i = 0; i < collection.length; i++) {
collection[i].innerHTML = result;
}
</script>
</body> </body>
</html> </html>

+ 9
- 0
site/text_functions.php View File

<?php

function highlight_search_terms($array, $search_term){
$replacement = "<span class='search_term'>$search_term</span>";
$result = str_ireplace($search_term, $replacement, $array);
return $result;
}

?>

Loading…
Cancel
Save