Jump to content

Google like search results


lwc

Recommended Posts

I want to have Google like search results. That means:
1) Highlighting the searched keywords, but still only presenting the phrases around them and not the entire page.
2) Presenting only the sentences in which the searched keywords are in. And keep in mind those sentences could be:
2)A. At the start of the page.
2)B. At the middle of the page.
2)C. At the end of the page.

Currently, I managed to do just the highlighting, but even that came with a price - it forces upper/lower capitalization based on the search. For example, if you looked for the word "php", every word that is spelled "PHP" would be changed to "php" in order to be highlighted.
Or in PHP language:
[code]$results = str_ireplace($searchword, '<font color=red>' . $searchword . '</font>', $results);[/code]
I had to use str_[b]i[/b]replace because otherwise it's a case sensitive search, which I don't want!

So again, what I want is just like Google would have it: for example, searching for the word "php" would also highlight the word "PHP", but without turning it into "php".

Thanks!
Link to comment
Share on other sites

use regular expressions like [url=http://www.php.net/preg_replace]preg_replace()[/url]

ex
[code=php:0]<?php

$string = "Highlight everything with php, like, PhP and www.phpfreaks.com";

$searchword = "php";
echo preg_replace("/($searchword)/is", '<span style="color: #ff0000">\\1</span>', $string);

?>[/code]
Link to comment
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.