Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


Highlighted search

 

This script was sent to us as a request when we wanted a script that highlighted text we searched for. The demonstartion shows this but also shows a drawback as it finds and highlights the phrase in a completely different word.

 

 

<?php
function highlight_search($search_words, $message)
{
$bgcolor = "yellow";
foreach ($search_words as $search_word)
{
$message = eregi_replace("($search_word)", "<span style=\"background-color: $bgcolor;\">\\1</span>", $message);
};
return $message;
};

$message = "some sample text to search and to highlight and stop";
$search = "to";

print highlight_search(explode(" ", $search), $message);
?>


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Blinking text(C)
pop up only once(Javascript)
Javascript version(Javascript)
display services in an excel spreadsheet(VBScript)
Split a string(PHP)
radio button redirection(ASP)
Open and display a text file(ASP)
Display when a page was last modified(PHP)

    




Copyright © 2003 by programmershelp.co.uk