Jump to content


Photo

Simple search


  • Please log in to reply
11 replies to this topic

#1 carnold

carnold
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 April 2006 - 05:10 PM

Hello all! New to php and the groups here at phpfreaks. I have a web site that has a html Bible on it. I would like to know how to create a search form that will search all the books of that online Bible. For instance, you goto the website and type in "romans" and then click on "search". It then should return all referneces of the word "romans".
I did look through the "scripts" section here but found dead links. Also did a "search" throught the forums but did not see what i needed. Let me know if anyone needs the site link. Thanks for any help.

Chris

#2 djnrempel

djnrempel
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 04 April 2006 - 05:35 PM

[!--quoteo(post=361608:date=Apr 4 2006, 12:10 PM:name=chrisa)--][div class=\'quotetop\']QUOTE(chrisa @ Apr 4 2006, 12:10 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hello all! New to php and the groups here at phpfreaks. I have a web site that has a html Bible on it. I would like to know how to create a search form that will search all the books of that online Bible. For instance, you goto the website and type in "romans" and then click on "search". It then should return all referneces of the word "romans".
I did look through the "scripts" section here but found dead links. Also did a "search" throught the forums but did not see what i needed. Let me know if anyone needs the site link. Thanks for any help.

Chris
[/quote]

How you search your bible greatly depends on how that bible is stored - is it in a database? Multiple html pages? Where did you get this bible and could you post a link?

#3 carnold

carnold
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 April 2006 - 07:21 PM

[!--quoteo(post=361616:date=Apr 4 2006, 12:35 PM:name=Dan R.)--][div class=\'quotetop\']QUOTE(Dan R. @ Apr 4 2006, 12:35 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How you search your bible greatly depends on how that bible is stored - is it in a database? Multiple html pages? Where did you get this bible and could you post a link?
[/quote]

Sure, the Bible is stored in its own directory and is multiple files. Link is www.mytimewithgod.net/126. Thanks for the help.

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 04 April 2006 - 07:36 PM

Looks like you are using some speedbible software. In order to do a search we need to knowwhat format the files are in. You said they are in their own directory but what kind of files are they. text, csv, ect.

Ray

#5 carnold

carnold
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 April 2006 - 07:41 PM

[!--quoteo(post=361679:date=Apr 4 2006, 02:36 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Apr 4 2006, 02:36 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Looks like you are using some speedbible software. In order to do a search we need to knowwhat format the files are in. You said they are in their own directory but what kind of files are they. text, csv, ect.

Ray
[/quote]

Oh sorry, yes speedbible from johnhurt.com. They are htm files. The links to the chapters do work, so if you click any chapter in any book, in your address bar it will display the full path including the file extension.

#6 djnrempel

djnrempel
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 04 April 2006 - 07:52 PM

Then you'll need a script that opens each file, and then checks whether and where that file contains the search terms. Read through the PHP documentation on file / directory functions. To actually find and report stuff, you'll need to use something like strstr or the more powerful ereg or preg_match. Best just to read up on those functions and hack away at it.

It would be a lot easier and faster (computer-wise) if the bible was in a database such as MySQL.

Just noticed that JohnHurt.com has some search tool - maybe he'll share it with you too.

#7 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 04 April 2006 - 07:52 PM

Problem with that is you would have to search for text inside a file, on top of that they are html files so you would have strip all html tags out. Also I imagine there are multiple folders uder the folder they are in.

if you can give your file structure it may help out

Ray

#8 carnold

carnold
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 April 2006 - 08:05 PM

[!--quoteo(post=361691:date=Apr 4 2006, 02:52 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Apr 4 2006, 02:52 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Problem with that is you would have to search for text inside a file, on top of that they are html files so you would have strip all html tags out. Also I imagine there are multiple folders uder the folder they are in.

if you can give your file structure it may help out

Ray
[/quote]

No, they are under 1 folder. Structure: wwwroot/kjvdict/then all the htm files. What way would you reccomend to search?

#9 DrDre

DrDre
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 04 April 2006 - 08:24 PM

Ok so I was bored (even tho i got tons of work, guess you can consider it generous? :P) And basically coded the entire thing for you.

<?php
$dir = "../kjvdict";
$books = Array(
    1  => 'Genesis',
    2  => 'Exodus',
    3  => 'Leviticus',
    4  => 'Numbers',
    5  => 'Deuteronomy',
    6  => 'Joshua',
    7  => 'Judges',
    8  => 'Ruth',
    9  => '1st Samuel',
    10  => '2nd Samuel',
    11 => '1st Kings',
    12 => '2nd Kings',
    13 => '1st Chronicles',
    14 => '2nd Chronicles',
    15 => 'Ezra',
    16 => 'Nehemiah',
    17 => 'Esther',
    18 => 'Job',
    19 => 'Psalms',
    20 => 'Proverbs',
    21 => 'Ecclesiastes',
    22 => 'Song of Solomon',
    23 => 'Isaiah',
    24 => 'Jeremiah',
    25 => 'Lamentations',
    26 => 'Ezekiel',
    27 => 'Daniel',
    28 => 'Hosea',
    29 => 'Joel',
    30 => 'Amos',
    31 => 'Obadiah',
    32 => 'Jonah',
    33 => 'Micah',
    34 => 'Nahum',
    35 => 'Habakkuk',
    36 => 'Zephaniah',
    37 => 'Haggai',
    38 => 'Zechariah',
    39 => 'Malachi',
    40 => 'Matthew',
    41 => 'Mark',
    42 => 'Luke',
    43 => 'John',
    44 => 'Acts',
    45 => 'Romans',
    46 => '1st Corinthians',
    47 => '2nd Corinthians',
    48 => 'Galatians',
    49 => 'Ephesians',
    50 => 'Philippians',
    51 => 'Colossians',
    52 => '1st Thessalonians',
    53 => '2nd Thessalonians',
    54 => '1st Timothy',
    55 => '2nd Timothy',
    56 => 'Titus',
    58 => 'Philemon',
    57 => 'Hebrews',
    59 => 'James',
    60 => '1st Peter',
    61 => '2nd Peter',
    62 => '1st John',
    63 => '2nd John',
    64 => '3rd John',
    65 => 'Jude',
    66 => 'Revelation'
);



$id=1;
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
   if ($dh = @opendir($dir)) {
       while (($file = @readdir($dh)) !== false) {
               //FRMB01C007.htm
            if(substr($file,0,4) == 'FRMB'){
                $book=intval(substr($file,4,2));
                $ch = intval(substr($file,6,3));
                if(strstr(strtolower(file_get_contents($dir.'/'.$file)),strtolower($_POST['indata']))){
                    $id++;
                    $results[$id]= $id.". <a href='".$dir.'/'.$file."'>Book: ".$books[$book]." - Chapter: ".$ch."</a><br>";
                }
            }
       }
       closedir($dh);
   }
}
echo "<h3>".($id-1)." Result".(($id-1) == 1 ? '' : 's')." Found.</h3><br>\n";
echo join("\n",$results);
?>
Set an array for each book (yeah i had to number each of those >.<) And read each file and if it finds the search term, print the book and chapter found in.

Should be no errors.. Least zend reported none. unless i messed up on the substr's.

hope it works.
[a href="http://forums.fanetworks.net" target="_blank"][/a]
» faNetworks Webmaster. [[a href="http://fanetworks.net" target="_blank"]fanetworks.net[/a]]
» faSoftware Developer [[a href="http://software.fanetworks.net" target="_blank"]software.fanetworks.net[/a]]
» faForums - php Resource + more [[a href="http://forums.fanetworks.net" target="_blank"]forums.fanetworks.net[/a]]
» Experienced php Coder - Ill help anyone I can if I have time ;)

#10 carnold

carnold
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 April 2006 - 08:39 PM

[!--quoteo(post=361712:date=Apr 4 2006, 04:24 PM:name=DrDre)--][div class=\'quotetop\']QUOTE(DrDre @ Apr 4 2006, 04:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Ok so I was bored (even tho i got tons of work, guess you can consider it generous? :P) And basically coded the entire thing for you.

<?php
$dir = "../kjvdict";
$books = Array(
    1  => 'Genesis',
    2  => 'Exodus',
    3  => 'Leviticus',
    4  => 'Numbers',
    5  => 'Deuteronomy',
    6  => 'Joshua',
    7  => 'Judges',
    8  => 'Ruth',
    9  => '1st Samuel',
    10  => '2nd Samuel',
    11 => '1st Kings',
    12 => '2nd Kings',
    13 => '1st Chronicles',
    14 => '2nd Chronicles',
    15 => 'Ezra',
    16 => 'Nehemiah',
    17 => 'Esther',
    18 => 'Job',
    19 => 'Psalms',
    20 => 'Proverbs',
    21 => 'Ecclesiastes',
    22 => 'Song of Solomon',
    23 => 'Isaiah',
    24 => 'Jeremiah',
    25 => 'Lamentations',
    26 => 'Ezekiel',
    27 => 'Daniel',
    28 => 'Hosea',
    29 => 'Joel',
    30 => 'Amos',
    31 => 'Obadiah',
    32 => 'Jonah',
    33 => 'Micah',
    34 => 'Nahum',
    35 => 'Habakkuk',
    36 => 'Zephaniah',
    37 => 'Haggai',
    38 => 'Zechariah',
    39 => 'Malachi',
    40 => 'Matthew',
    41 => 'Mark',
    42 => 'Luke',
    43 => 'John',
    44 => 'Acts',
    45 => 'Romans',
    46 => '1st Corinthians',
    47 => '2nd Corinthians',
    48 => 'Galatians',
    49 => 'Ephesians',
    50 => 'Philippians',
    51 => 'Colossians',
    52 => '1st Thessalonians',
    53 => '2nd Thessalonians',
    54 => '1st Timothy',
    55 => '2nd Timothy',
    56 => 'Titus',
    58 => 'Philemon',
    57 => 'Hebrews',
    59 => 'James',
    60 => '1st Peter',
    61 => '2nd Peter',
    62 => '1st John',
    63 => '2nd John',
    64 => '3rd John',
    65 => 'Jude',
    66 => 'Revelation'
);
$id=1;
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
   if ($dh = @opendir($dir)) {
       while (($file = @readdir($dh)) !== false) {
               //FRMB01C007.htm
            if(substr($file,0,4) == 'FRMB'){
                $book=intval(substr($file,4,2));
                $ch = intval(substr($file,6,3));
                if(strstr(strtolower(file_get_contents($dir.'/'.$file)),strtolower($_POST['indata']))){
                    $id++;
                    $results[$id]= $id.". <a href='".$dir.'/'.$file."'>Book: ".$books[$book]." - Chapter: ".$ch."</a><br>";
                }
            }
       }
       closedir($dh);
   }
}
echo "<h3>".($id-1)." Result".(($id-1) == 1 ? '' : 's')." Found.</h3><br>\n";
echo join("\n",$results);
?>
Set an array for each book (yeah i had to number each of those >.<) And read each file and if it finds the search term, print the book and chapter found in.

Should be no errors.. Least zend reported none. unless i messed up on the substr's.

hope it works.
[/quote]

Dude! You are the man!! I can now run searches, on the searches i have done so far, it returns results but has this error at the top of the page:
Warning: file_get_contents(../kjvdict/FRMB01C010.htm~): failed to open stream: Permission denied in /srv/www/htdocs/wp-includes/search.php on line 83
70 Results Found.
I have chmod file to owner full and other full permissions. I have looked at line 83 in search.php, lol, but it is foreign to me. Thanks again!!!

#11 DrDre

DrDre
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 04 April 2006 - 08:45 PM

Hmm you got some tmp file or something in there that it cant access.

if (is_dir($dir)) {
   if ($dh = @opendir($dir)) {
       while (($file = @readdir($dh)) !== false) {
               //FRMB01C007.htm
            if(substr($file,0,4) == 'FRMB' && substr($file,strlen($file)-4,4) == '.htm'){
                $book=intval(substr($file,4,2));
                $ch = intval(substr($file,7,3));
                $data = @file_get_contents($dir.'/'.$file);
                if($data && strstr(strtolower($data),strtolower($_POST['indata']))){
                    
                    $results[$id]= $id.". <a href='".$dir.'/'.$file."'>Book: ".$books[$book]." - Chapter: ".$ch."</a><br>";
                    $id++;
                }
            }
       }
       @closedir($dh);
   }
}
echo "<h3>".($id-1)." Result".(($id-1) == 1 ? '' : 's')." Found.</h3><br>\n";
echo join("\n",$results);
?>

That should fix all the problems. Then customize it as you see fit to make it look better :)
[a href="http://forums.fanetworks.net" target="_blank"][/a]
» faNetworks Webmaster. [[a href="http://fanetworks.net" target="_blank"]fanetworks.net[/a]]
» faSoftware Developer [[a href="http://software.fanetworks.net" target="_blank"]software.fanetworks.net[/a]]
» faForums - php Resource + more [[a href="http://forums.fanetworks.net" target="_blank"]forums.fanetworks.net[/a]]
» Experienced php Coder - Ill help anyone I can if I have time ;)

#12 carnold

carnold
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 07 April 2006 - 05:30 PM

[!--quoteo(post=361727:date=Apr 4 2006, 04:45 PM:name=DrDre)--][div class=\'quotetop\']QUOTE(DrDre @ Apr 4 2006, 04:45 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hmm you got some tmp file or something in there that it cant access.

if (is_dir($dir)) {
   if ($dh = @opendir($dir)) {
       while (($file = @readdir($dh)) !== false) {
               //FRMB01C007.htm
            if(substr($file,0,4) == 'FRMB' && substr($file,strlen($file)-4,4) == '.htm'){
                $book=intval(substr($file,4,2));
                $ch = intval(substr($file,7,3));
                $data = @file_get_contents($dir.'/'.$file);
                if($data && strstr(strtolower($data),strtolower($_POST['indata']))){
                    
                    $results[$id]= $id.". <a href='".$dir.'/'.$file."'>Book: ".$books[$book]." - Chapter: ".$ch."</a><br>";
                    $id++;
                }
            }
       }
       @closedir($dh);
   }
}
echo "<h3>".($id-1)." Result".(($id-1) == 1 ? '' : 's')." Found.</h3><br>\n";
echo join("\n",$results);
?>

That should fix all the problems. Then customize it as you see fit to make it look better :)
[/quote]

Sorry for the delay (my mom was in a car accident). Yea, so i changed some permissions and it worked without the last bit of code. Thank you so much for the help! Trying to "style" it now to look like my site :)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users