Jump to content

Simple search


carnold

Recommended Posts

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
Link to comment
Share on other sites

[!--quoteo(post=361608:date=Apr 4 2006, 12:10 PM:name=chrisa)--][div class=\'quotetop\']QUOTE(chrisa @ Apr 4 2006, 12:10 PM) [snapback]361608[/snapback][/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?
Link to comment
Share on other sites

[!--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) [snapback]361616[/snapback][/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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[!--quoteo(post=361679:date=Apr 4 2006, 02:36 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Apr 4 2006, 02:36 PM) [snapback]361679[/snapback][/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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[!--quoteo(post=361691:date=Apr 4 2006, 02:52 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Apr 4 2006, 02:52 PM) [snapback]361691[/snapback][/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?
Link to comment
Share on other sites

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.

[code]<?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);
?>[/code]
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.
Link to comment
Share on other sites

[!--quoteo(post=361712:date=Apr 4 2006, 04:24 PM:name=DrDre)--][div class=\'quotetop\']QUOTE(DrDre @ Apr 4 2006, 04:24 PM) [snapback]361712[/snapback][/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.

[code]<?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);
?>[/code]
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!!!
Link to comment
Share on other sites

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

[code]
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);
?>[/code]

That should fix all the problems. Then customize it as you see fit to make it look better :)
Link to comment
Share on other sites

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

[code]
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);
?>[/code]

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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.