michaellunsford Posted January 15, 2007 Share Posted January 15, 2007 There are a few websites out there that highlight the search terms you used to find them. I googled it and found [url=http://www.holovaty.com/blog/archive/2002/08/13/0040]this guy[/url]. It reads like a bragging blog, but he conveniently leaves out the "how to". Likewise, other "javascript" versions I found in google didn't highlight any of my search terms.What I want to do is for internal MySQL searches, so I'll be looking at $_POST variables, but the idea is the same. I'd like to highlight any $_POSTed search terms. Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 15, 2007 Share Posted January 15, 2007 If it's for internal, I would simply create a Highlighter object that would be able to be initiated on each page with a list of words. As the page content is generated, run a Parse() function in your Highlighter on the text, doing a str_replace() with the search terms, and surrounding those words with a span that has your highlighting class in your CSS applied to it. Once that's done, when your page is printed out, those matching words will be highlighted appropriately.Now, as to a javascript version, it would work the same way, except you would simply want to loop through all your tags, running the parsing function on the innerHTML of each one as you went. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks for the reply. It looks like str_replace works on mixed subjects. So I could feed it a mysql_fetch_assoc array, and it should work. experiment time. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 16, 2007 Author Share Posted January 16, 2007 PS> the site that does it...[url=http://www.google.com/search?client=safari&rls=en&q=htaccess+mod+rewrite+options&ie=UTF-8&oe=UTF-8]Google Search[/url]top result is [url=http://corz.org/serv/tricks/htaccess2.php].htaccess tips and tricks[/url]looks like javascript is rewriting theirs -- but my experiments with PHP are working wonderfully. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.