SunQuest
           Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials
View Poll Results: Did you find this useful?
Yes 0 0%
No 0 0%
Voters: 0. You may not vote on this poll


Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old May 3rd, 2007, 10:56 AM
augustusgloo's Avatar
augustusgloo augustusgloo is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 123 augustusgloo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 2 m 32 sec
Reputation Power: 2
Talking REQUEST: Simple search without SQL

Hi
I am Hamish and I am 12.
I programmed this script all myself.
As the title says, there is no SQL needed, no HTML/PHP code displayed and titles as well.
First make a form (GET or POST) with an input name of searchstring . Now we start to program the script.

We start the PHP session and head straight off by doing a simple query to tell if anything has been entered and echoing a search header.

PHP Code:
<?php
if ($_REQUEST['searchstring']){echo "Search Results:";


Now we define some variables. First the contents file. This is in the format of:
Code:
filename.ext|Title
filename.ext|Title

etc. You can rename the contents file to your choice.
Next we put all the contents lines into an array with the file function.
After that we do a foreach for all the lines and get rid of the newline character.
We also put in the unique title feature, by listing variables and splitting by a slashed-out pipe. We need the [0] at the end of the split string so as not to generate 'Array' errors. Finally we open the filename part of the list.

PHP Code:
 $contents "contents.txt";
$filearr file($contents);
foreach(
$filearr as $file){
$line explode("
"
$file);
list(
$checkfile$title) = split("\|"$line[0]);
$check file($checkfile); 


Next we do an fopen and fread with an if to tell if the searchstring is contained in the file.

PHP Code:
 $fr fopen($checkfile"r");$content fread($frfilesize($checkfile));
if (
eregi($_REQUEST['searchstring'], $content)){ 


We put in a nice file header and use the $check variable we defined using file function with a foreach. We then strip all the tags from that. Next we check if the searchstring is in that line.

PHP Code:
echo "<font size='5'><a href='" $checkfile "'>" $title 
"</a></font><br>";
foreach(
$check as $checking){
$checkline strip_tags($checking);
if(
eregi($_REQUEST['searchstring'], $checkline)){ 


Here comes the good part.We explode the line by a space, so exploding it into words. We then echo a ... for the line start and for each of the words, check if the searchstring is in them. If it is, then echo it in bold. Otherwise, just echo it.

PHP Code:
 $word explode(" "$checkline);
echo 
"...";
foreach(
$word as $checkword){
if (
eregi($_REQUEST['searchstring'], $checkword)){
echo 
"<b>$checkword </b>";
}else{
echo 
"$checkword "


Now all we do is finish off all the many constructs, add some new lines and finish the PHP session.

PHP Code:
}
}
echo
"...<br>";}}echo "<br>";}}}
?> 


Here is the whole code:

PHP Code:
<?php
if ($_REQUEST['searchstring']){echo "Search Results:<br><br>";
$contents "contents.txt";
$filearr file($contents);
foreach(
$filearr as $file){
$line explode("
"
$file);
list(
$checkfile$title) = split("\|"$line[0]);
$check file($checkfile);
$fr fopen($checkfile"r");$content fread($frfilesize($checkfile));
if (
eregi($_REQUEST['searchstring'], $content)){
echo 
"<font size='5'><a href='" $checkfile "'>" $title 
"</a></font><br>";
foreach(
$check as $checking){
$checkline strip_tags($checking);
if(
eregi($_REQUEST['searchstring'], $checkline)){
$word explode(" "$checkline);
echo 
"...";
foreach(
$word as $checkword){
if (
eregi($_REQUEST['searchstring'], $checkword)){
echo 
"<b>$checkword </b>";
}else{
echo 
"$checkword ";
}
}
echo
"...<br>";}}echo "<br>";}}}
?>


I hope you have found this useful. You can use the poll included, 1 for yes, 2 for no. Please feel free to drop me a line at hamishcool3@yahoo.co.uk

Cheers,
Hamish

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > REQUEST: Simple search without SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway