Guest User

Untitled

a guest
Aug 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. Tidying search results from database php
  2. <?php
  3.  
  4. foreach ($searchcontent ->result() as $row)
  5. {
  6. echo $title
  7. echo $content
  8. }
  9. ?>
  10.  
  11. $keyword = THESEARCHEDKEYWORD;
  12. $pattern = "/([^a-z])$keyword([^a-z])/i";
  13. $highlight = '<span class="highlight">' . $keyword . '</span>';
  14. foreach ($searchcontent->result() as $row)
  15. {
  16. $title = preg_replace($pattern, "$1$highlight$2", $title);
  17. $content = preg_replace($pattern, "$1$highlight$2", $content);
  18. echo $title;
  19. echo $content;
  20. }
  21.  
  22. .highlight
  23. {
  24. font-weight: bold;
  25. background-color: yellow;
  26. }
Add Comment
Please, Sign In to add comment