Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm creating a serach function and have got it to find a particular term in a document or web page. I'm now trying to get it to display the term found and the text either side of it but all I can get it to do is output the whole page contents. The page contents get stored in the variable $contents. I was wondering if anybody could help me, the code i'm using is displayed below, it is linked to from a page which just displays the results in a table.Code: Select all
<?php
/*
* Complete the search class below
*/
class SiteSearch {
function return_result () {
$filename = $_GET['url'];
$h=date("H",$t)-4;
$date = date("l dS \of F Y $h:i:s A");
$term = $_GET['term'];
$depth = $_GET['depth'];
$result = array();
$handle = fopen($filename, "rb");
$preg = "/$term/";
preg_match_all(trim($preg), file_get_contents($filename), $out, PREG_PATTERN_ORDER);
$size = sizeof($out[0]);
$i=0;
while ($i < $size) {
$title = $out[0][$i];
$title = trim(strip_tags($title));
$contents = file_get_contents($filename);
$result[$i] = array (
"title" => ($i+1).": ". $title,
"date" => $date,
"content" => $contents,
"url" => $filename
);
$i++;
}
return $result;
fclose($handle);
}
}
?>onion2k | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]