Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tidying search results from database php
- <?php
- foreach ($searchcontent ->result() as $row)
- {
- echo $title
- echo $content
- }
- ?>
- $keyword = THESEARCHEDKEYWORD;
- $pattern = "/([^a-z])$keyword([^a-z])/i";
- $highlight = '<span class="highlight">' . $keyword . '</span>';
- foreach ($searchcontent->result() as $row)
- {
- $title = preg_replace($pattern, "$1$highlight$2", $title);
- $content = preg_replace($pattern, "$1$highlight$2", $content);
- echo $title;
- echo $content;
- }
- .highlight
- {
- font-weight: bold;
- background-color: yellow;
- }
Add Comment
Please, Sign In to add comment