pixeltrace Posted September 24, 2007 Share Posted September 24, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/70428-how-to-search-without-database/ Share on other sites More sharing options...
LemonInflux Posted September 24, 2007 Share Posted September 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/70428-how-to-search-without-database/#findComment-353831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.