473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Special Search

Okay, I've just created this PHP script and know to finish it off, I
want to add a search feature. I want the search to search in a folder
called "songs/". The songs/ folder is full of .txt files all allocated
in subfolders of songs/. It is supposed to work like a regular search
engine. But the results need a little tweaking: if there's a file
called song/s/sing-a-song.txt, I want the PHP script to print a link to
index.php?song=sing-a-song. The value of the song query in the link
will always be the same as the file name, excluding the file extention:

Another example:
There's a text file: songs/b/better-is-one-day.txt
I want the PHP script to print a link to
index.php?song=better-is-one-day
I tried creating a script that does this, but it has proved futile. I
was hoping if you could help me, or at least guide me. All replies
would be appretiated.

Nov 2 '06 #1
3 1189
Hope I understood and it helps;
1st STEP:
You need a recursive function for subdirectory handling.
recursive function means "a function calls himself" in a loop.
usually an infinite loop but not here. search for similar algorythims
to handle every subdirectories one by one.
"
function recursive_func($basedir) {
$handle =opendir($basedir);
while ($file = readdir($handle)) {
do your compare and other stuff here;
if (is_dir($file)) {
recursive_func($file);
}
}
}

2nd STEP:
use a regular expression for keyword search in file names for
comparison.
use like ereg() or eregi() functions. they explained in references.
"if (ereg("key", $filename)) { print "<a>form your URL here</a>"; }"
esarch better examples.

Nov 2 '06 #2
On 2 Nov 2006 14:10:55 -0800, ma*****@gmail.com wrote:
>Okay, I've just created this PHP script and know to finish it off, I
want to add a search feature. I want the search to search in a folder
called "songs/". The songs/ folder is full of .txt files all allocated
in subfolders of songs/. It is supposed to work like a regular search
engine. But the results need a little tweaking: if there's a file
called song/s/sing-a-song.txt, I want the PHP script to print a link to
index.php?song=sing-a-song. The value of the song query in the link
will always be the same as the file name, excluding the file extention:
<snip>
>I tried creating a script that does this, but it has proved futile. I
was hoping if you could help me, or at least guide me. All replies
would be appretiated.
First I would advice you to move to a database, going through all
those files will be hard on performance, unless it's just a private
script or something only a few people will use.

Second, I need you to describe the file structure a bit more, how
exactly are the files positioned?

--
best regards,
Martin Mouritzen.
http://www.siteloom.dk
Nov 3 '06 #3
A database would be the optimal solution at any rate but, assuming the
songs dir is in the current directory and $song_name is set:

<?php
function getfilearray($start) {
$dir=opendir($start);
while (false !== ($found=readdir($dir))) { $getit[]=$found; }
foreach($getit as $num =$item) {
if (is_dir($start.$item) && $item!="." && $item!="..") {
$output["{$item}"]=filearray($start.$item."/"); }
if (is_file($start.$item)) { $output["{$item}"]="FILE"; }
}
closedir($dir);
return $output;
};

$f_letter = substr($song_name,0,1);
if(is_dir("./songs/".$f_letter)){
$files = getfilesarray("./songs/".$fletter."/");
foreach($files as $name =$type){
if($name==$songname.".txt" && $type = "FILE")
$found = true;
};
};
};
if($found){
echo "<a href=\"index.php?song=$song_name\">$song_name</a>";
};
?>

Nov 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Diane Blevins | last post by:
sFt ----HUISORc8AeipkQw2ckY Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html> <head> <style type=3D"text/css">.eyebrow { FONT-WEIGHT: bold; FONT-SIZE: 10px; TE=
50
by: The Bicycling Guitarist | last post by:
A browser conforming to HTML 4.0 is required to recognize &#number; notations. If I use XHTML 1.0 and charset UTF-8 though, does &eacute; have as much support as é ? Sometimes when I run...
7
by: arno | last post by:
Hi, I want to search a substring within a string : fonction (str, substr) { if (str.search(substr) != -1) { // do something } }
9
by: Larry | last post by:
OK, I've been searching around the net for numerous hours and seem to just be getting more confused about handling special characters. In my host's configuration MagicQuotes is ON. (I understand...
0
by: Luis Corrales | last post by:
Hi all, I have a problem when searching for text with special characters in e-mails in an IMAP server. I'm using imaplib in python 2.4.3 and I can't get this code working: # first connect and...
2
by: Diilb | last post by:
I am using DOM to create an rss feed. The problem I am running into is "special characters" such as é è ç. If I try adding them to the XML as character data (CData), DOM chokes and throws out...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
1
by: Ragavendran | last post by:
Hi, I am using this method for search: Query =org.apache.lucene.queryParser.QueryParser.parse(String arg0) throws ParseException Hits = org.apache.lucene.search.Searcher.search(Query query,...
5
by: Joseph Barillari | last post by:
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other...
3
by: thesti | last post by:
hi, how to search a string in a table that contain a special character ? for example i want to search fo a string "D'Crepes" in a field of a table. i've tried using the following sql from vb...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.