![]() |
highlight searched string - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: highlight searched string (/showthread.php?tid=3824) Pages:
1
2
|
highlight searched string - El Forum - 10-23-2007 [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. highlight searched string - El Forum - 10-24-2007 [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); ?> highlight searched string - El Forum - 10-24-2007 [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(){ highlight searched string - El Forum - 10-24-2007 [eluser]nirbhab[/eluser] Thank you guys, let me try implementing your ideas and code, concept seems right! highlight searched string - El Forum - 10-24-2007 [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/displaying_search_results_with_php I'm using php5, please explain if str_replace function will works in php4 or not .. thx highlight searched string - El Forum - 10-24-2007 [eluser]xwero[/eluser] I'm using str_replace in php4 there is no problem with it. highlight searched string - El Forum - 10-24-2007 [eluser]cinewbie81[/eluser] cheers .. btw, is there anyway for me to IGNORE the CASE SENSITIVITY using the str_replace() function mentioned above ??? highlight searched string - El Forum - 10-24-2007 [eluser]xwero[/eluser] using preg_replace ![]() highlight searched string - El Forum - 10-24-2007 [eluser]John_Betong[/eluser] Why not use CodeIgniter's Text helper? Code: highlight_phrase() highlight searched string - El Forum - 10-24-2007 [eluser]xwero[/eluser] [quote author="John_Betong" date="1193248162"]Why not use CodeIgniter's Text helper? [/quote] It uses preg_replace ![]() |