PHP Classes

File: demo.php

Recommend this page to a friend!
  Classes of tony  >  Safe keyword highlight  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: Example that shows an HTML text with and without highlighting
Class: Safe keyword highlight
Text keyword highlight within HTML tags
Author: By
Last change: new relese
Date: 14 years ago
Size: 1,690 bytes


Class file image Download
 * DEMO for highlighter.php CLASS by Bojidar Naydenov a.k.a Bojo ( & Antony Raijekov a.k.a Zeos (
 * This class highlights text matches a search string (keyword) in html based documents, without destroying html-tags.
 * This was necessary to scan database-entry written in html by keywords, and display them in another style.

include("highlighter.class.php"); //include class

 * DEMO code
// assume $text is content of article ot some other text
$text = "<div>text <table>
        <td valign=top> <IMG src=\"\" title=\"test\">
    </table> <B>test</B> text <a href=\"test.php\">tester</a> <A HREF=\"index.php?seek=test\" style=\"color:green\">test is tester but is not good</A> text.Test.</div>"

//create hightlight instance class, with keyword(test) and replacement (<u>{keyword}</u>)
//NOTE: the {keyword} in second argument (replacement) is alias for matching keyword.
$h = new highlight ('test','<u style="background-color:#B5B5B5">{keyword}</u>');
//print original text
print $text;

//print it proceed with hightlight
print $h->process($text);