Jump to content

how to search without database


pixeltrace

Recommended Posts

Hi,

 

i am developing a site and everything on the site is static

meaning no database.

 

now, they wanted to add a search tool bar

thats is only meant to search by keywords

 

my problem is i dont know how to do it because i have done it before.

 

hope anyone here can help me

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/70428-how-to-search-without-database/
Share on other sites

You could, in theory, do it with PHP.

 

First off, create a page called pages.db.php.

 

Put the content for each page on 1 line per page. For example:

 

page1contentblahblahblah

page2contentwithslightlymoreblah

page 3 content with spaces

 

Ok, then, on each of your pages, use

 

$pages = file_get_contents('pages.db.php');

Then,

$page = explode('\n', $pages);

 

What you now have, is a $page array. Then, where you want the content on your page, <?php echo $page['number of page here']; ?>

 

'number of page' being the nth line in your sequence, eg. The home may be on the first line, and therefore, <?php echo $page[0]; ?> would be the code to use. Then, for the search engine:

 

create search.htm and search.php.

 

In search.htm, create a form with a textbox (called searchbar) and a submit button, the action being search.php. In search.php, use the following code(s):

 

$search = $_POST['searchbar'];

$page = file_get_contents('pages.db.php');
$pages = explode('\n', $page);
foreach($pages as $pageinfo){
$pagetags = explode(' ', $pageinfo);
foreach($pagetags as pagetag){
if($search = $pagetag){
echo $pages;
}
}
}

 

Haven't checked it, but that'll be the basis of what you need. It converts all the page's content into search tags, for your engine to pick up. Very simple, but I guess that's the way around it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.