Warning: eregi(): REG_EMPTY

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
screwcork
Forum Newbie
Posts: 16
Joined: Thu Apr 13, 2006 3:25 am
Location: Oslo - Norway

Warning: eregi(): REG_EMPTY

Post by screwcork »

I'm kinda new with this whole PHP thing, and i'm currently making an internal search engine for a website. Actually I followed a tutorial on it and wrote the whole thing according to plan.. But when i finally tried the thing it wouldn't work.

Here's what i get when i search for something:

Warning: eregi(): REG_EMPTY in /home/prexide/public_html/screwcork/TCS/search.php on line 25

Warning: eregi(): REG_EMPTY in /home/prexide/public_html/screwcork/TCS/search.php on line 25
No result No result


and here's the code i use in full:

Code: Select all

<?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)){  //this is the line who bugs my brain!!!
$title=$m["1"];
}
else{
$title="No result";
}
$array[]="$dir/$file $title";
}
}
}
}
}
}
$array=array();
listFiles(".","$keyword",$array);
foreach($array as $value){
list($filedir,$title)=split("[ ]",$value,"2");
echo "$title "."
\n";
}
?>
Please help a newb!
Last edited by screwcork on Thu Apr 13, 2006 3:41 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

the error message pretty much tells you what the problem is

Code: Select all

if(eregi("",$data,$m)){
What are you trying to achieve with that line because there is no pattern defined.

Code: Select all

if(eregi("some_pattern_here",$data,$m)){
screwcork
Forum Newbie
Posts: 16
Joined: Thu Apr 13, 2006 3:25 am
Location: Oslo - Norway

Post by screwcork »

Thank you for replying! :)
Pimptastic wrote:
What are you trying to achieve with that line because there is no pattern defined.

Code: Select all

if(eregi("some_pattern_here",$data,$m)){
I feel really stupid now, cause i don't really know what defining a pattern really means.
Anyways, I google'd a bit and decided to do this:

Code: Select all

if(eregi("search.php",$data,$m)){
And the error message dissappeared!

But.. (allways a but isn't it?)
The form cant seem to find anything :P

If I search something I know is somewhere in my directories, i get "No result"
If I search something I know is not in my directories, the search returns blank.. nothing at all! A completely white screen! :P

Is this script maybe just trash, or is it possible that i'm being even more stupid than earlier?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what are you trying to achieve?
screwcork
Forum Newbie
Posts: 16
Joined: Thu Apr 13, 2006 3:25 am
Location: Oslo - Norway

Post by screwcork »

hello again
Pimptastic wrote:what are you trying to achieve?
Well, I wish i knew! :P To be honest i'm not even sure what half the code mean! I just want the search engine to actually search, and list everything it finds!

Could you please take a look at:

http://www.tutorialized.com/tutorial/Cr ... gine/10207

and see if you get the point? It's not a long tutorial, and I think you'll get it, or possibly understand a bit more than i do!
Really don't wanna waste anyones time with my stupid questions, but i've been trying to google my way to an answer all night (which reminds me it's coffee time) and i'm just stuck in a mess of crap here! I don't know what defining a pattern means, and i do not know what i'm trying to achieve other than making the search engine actually search :P

Sorry for being a retard! ;P
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

The tutorial you were following was badly contrcuted. Htere is missing information becuase some of the HTMl elements were output as such, and not as tect on the page.

The line i mentioned above you read as follows

Code: Select all

if(eregi("<title>(.+)</title>",$data,$m)){
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

screwcork
Forum Newbie
Posts: 16
Joined: Thu Apr 13, 2006 3:25 am
Location: Oslo - Norway

Post by screwcork »

Once again, hello there! :)
Pimptastic wrote:The tutorial you were following was badly contrcuted. Htere is missing information becuase some of the HTMl elements were output as such, and not as tect on the page.

The line i mentioned above you read as follows

Code: Select all

if(eregi("<title>(.+)</title>",$data,$m)){
Ok, i tried what you suggested, and behold, it actually worked a bit better!
But I'm starting to realize I'm in way over my head here!

Now it posts the results, but not as links to the actual files as promised, just text! (Hooray, the files exist, but you cant see them) :P

And searches with no result still appear blank. Blank as in nothing at all!

I'm not even gonna ask for more help on this one. I'm having trouble to follow as it is, and i think that making this script work propperly as well as making it include friendly require a rather large rewrite, if not a full rewrite!

But I really appreciate the replies i got! I learned a bit more, and hopefully the links provided by Oren will point me in the right direction!

Thanks again for the help :)
Post Reply