Hello,
I'm wondering if this is possible: when my users search in a free text box and results are returned in php/mysql...is it possible to somehow highlight the words they searched for in the returned records?
thanks,
sage
Hello,
I'm wondering if this is possible: when my users search in a free text box and results are returned in php/mysql...is it possible to somehow highlight the words they searched for in the returned records?
thanks,
sage
Well I can say that I have never done this but, the first thing that came to my mind was this...
Maybe someone else knows of a better way of doing this... But ive never done search scripts, but the concept above would work...PHP Code:<?php
//Get the search string... search.php?q=content
$q = $_REQUEST['q'];
$content = "This is all of your content from your mysql database. Get it here however";
//Highlight the keywords
$updatedContent = str_replace($q, "<span style=\"background-color:yellow\">" . $q . "</span>", $content);
echo $updatedContent;
?>
Instead of using this line:
try using this instead so that the search is case-insensitive:Code:$updatedContent =str_replace($q, "<span style=\"background-color:yellow\">" . $q . "</span>", $content);
Hope this helpsCode:$updatedContent =str_ireplace($q, "<span style=\"background-color:yellow\">" . $q . "</span>", $content);
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design
Good thinking testing... That didnt even dawn on me...
Hello:
I just used str_ireplace for a search script but came across an issue. Here's my code:
The problem I'm seeing is that when I search for the word 'solar' and there are records in the database that match the result set changes the case of the word. So 'SOLAR' or 'Solar' is displayed on screen as 'solar.' I'd like to keep the case of the database record and not change it to whatever was put into the search field.PHP Code:str_ireplace($var, '<span class="highlight_pink">'.$var.'</span>', $FirstName);
Any ideas on what to do?
Thanks!
tryPHP Code:preg_replace('/('.$var.')/i', '<span class="highlight_pink">$1</span>', $FirstName);
[Jasme Library (Javascript Motion Effects)] My Site
/\/\@§†ê® §©®¡þ† /\/\@|{ê®
There are 10 kinds of people in the world, those that understand binary and those that don't.
Thank you Master Script Maker!!! That worked beautifully!
Your welcome! There's a button for thanks too.
[Jasme Library (Javascript Motion Effects)] My Site
/\/\@§†ê® §©®¡þ† /\/\@|{ê®
There are 10 kinds of people in the world, those that understand binary and those that don't.
Bookmarks