Login   Register  
PHP Classes
elePHPant
Icontem

File: highlighter.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of D U  >  Page highlighter  >  highlighter.php  >  Download  
File: highlighter.php
Role: Application script
Content type: text/plain
Description: highlight words in page
Class: Page highlighter
Highlight words in a webpage with regexp
Author: By
Last change: spelling errors
Date: 11 years ago
Size: 1,142 bytes
 

Contents

Class file image Download
<?
/*******************************************
using regexp you can highlight words inside a page

example url: 

http://localhost//highlighter.php?search=(word)&url=http://www.slashdot.com

this script is not safe, so you can also enter url=file and so 
people can sniff your sourcecode, so only use it on localhost or 
add some security.
******************************************/



$report="start\\n";
require 
"oo_file.inc.php";

$url=$_GET["url"];
if ( 
$url=="" ) { $url="http://www.slashdot.org"; }

print 
"<base href='$url'>";

$page=new File($url,"r");
  
$p=$page->read(80000000);
$page->close();
$p preg_replace("/\r\n|\n\r|\n|\r/"""$p);
 

// get all tags:
$rows=spliti("<",$p);
foreach( 
$rows as $nr=>$row ){
    if (
$nr==0
    {
        print 
$row;
    }
    else
    {
        if ( 
            
eregi$_GET["search"] , strip_tags$row) ) 
            
        )
        {
            list( 
$t1$t2 ) = split(">"$row,2);
            
$t2=eregi_replace$_GET["search"], "<span style='background-color:yellow;color:black' >\\0</span>"$t2 );
            print 
"<$t1  > $t2";
        } 
        else 
        {
            print 
"<".$row;
        }    
    }
}

$report.="end\\n";
?>