highlight searched string |
[eluser]nirbhab[/eluser]
hi, i am making a search engine module for my site, please suggest me a way to highlight the string or a sentence in searched output, eg. google after displaying the result bolds the string. Example: CodeIgniter - Open source PHP web application framework CodeIgniter: an open source Web Application Framework that helps you write PHP programs.
[eluser]Michael Wales[/eluser]
Just do a str_replace to apply a class to the string, then setup your CSS. [code] <?php $str = str_replace($query, '<span class="bold">' . $query . '</span>', $str); ?>
[eluser]xwero[/eluser]
My best guess is you would have to do it with javascript. The page where you display your results has the search string and based on that it searches for the words of that string. Code: $(function(){
[eluser]nirbhab[/eluser]
Thank you guys, let me try implementing your ideas and code, concept seems right!
[eluser]cinewbie81[/eluser]
[quote author="walesmd" date="1193224976"]Just do a str_replace to apply a class to the string, then setup your CSS. [code] <?php $str = str_replace($query, '<span class="bold">' . $query . '</span>', $str); ?>[/quote] I'm looking for the same thing .. thanks again .. but if I'm not mistaken, str_replace function is only works for php5 right ?? That's bcos i found it on other site, there's different version of code for different version of php .. please see the link below : http://www.whatstyle.net/articles/6/disp...s_with_php I'm using php5, please explain if str_replace function will works in php4 or not .. thx
[eluser]xwero[/eluser]
I'm using str_replace in php4 there is no problem with it.
[eluser]cinewbie81[/eluser]
cheers .. btw, is there anyway for me to IGNORE the CASE SENSITIVITY using the str_replace() function mentioned above ???
[eluser]John_Betong[/eluser]
Why not use CodeIgniter's Text helper? Code: highlight_phrase()
[eluser]xwero[/eluser]
[quote author="John_Betong" date="1193248162"]Why not use CodeIgniter's Text helper? [/quote] It uses preg_replace ![]() |
Welcome Guest, Not a member yet? Register Sign In |