Hi can some one help me please I am new to PHP and would like to use the script below as a search engine for a site I'm building. The error given when you submit the search is
Warning: eregi(): REG_EMPTY:dempty (sub)expression in W:\www\test\search.php on line 43
This appears to be a problem with this part of the script
if(eregi("",$data,$m))
{
$title=$m["1"];
}
else
The script does produce a list of links to pages containg the keywords but lists them as "no title" when it's meant to display the page title as the link.
Full script below
<?php
set_time_limit("600");
$keyword=trim($_POST["keyword"]);
if($keyword=="")
{
echo"Please enter your keyword";
exit;
}
function listFiles($dir,$keyword,&$array)
{
$handle=opendir($dir);
while(false!==($file=readdir($handle)))
{
if($file!="."&&$file!="..")
{
if(is_dir("$dir/$file"))
{
listFiles("$dir/$file",$keyword,$array);
}
else
{
$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
if(eregi("]+)>(.+)",$data,$b))
{
$body=strip_tags($b["2"]);
}
else
{
$body=strip_tags($data);
}
if($file!="search.php")
{
if(eregi("$keyword",$body))
{
if(eregi("",$data,$m))
{
$title=$m["1"];
}
else
{
$title="no title";
}
$array[]="$dir/$file $title";
}
}
}
}
}
}
$array=array();
listFiles(".","$keyword",$array);
foreach($array as $value)
{
list($filedir,$title)=split("[ ]",$value,"2");
echo "<a href=$filedir target=_blank>$title</a><br>";
}
?>
I hope this makes sense and would really appreciate any help anyone can offer, I have spent a lot of time trying to understand whats going wrong and why, but am afraid I'm still in the dark.
Many thanks
Keith