Shadowfox
02-15-2006, 04:49 PM
Hello everybody!
First of all, I should thank you in advance for reading this thread.
Please, help me if you can because it is urgent.
1. What do I want to do?
I wish to create a search <FORM> to search in the contents of a text file located somewhere on the server. I wish to be able to:
a) set a search criteria which is different from exact phrase
Example: Searching Blue monkey happy should find Happy blue monkey
b) set a search criteria with case INsensitive
Example: Searching HAPPY BlUe MonKeY should find Happy blue monkey
c) as the text file contains lines with a unique record on each; and on each line there are words separated by a TAB delimiter, I would like:
- if a part of the line in the file matches the search criteria, the WHOLE line has to be printed;
- results have to be printed in a <TABLE> with <TR> for every line match and <TD> for every word between the TAB delimiters in the file.
2. What have I done so far?
I got this code. It shows the contents of the text file in a table but all of them - not just the ones matching the search criteria...
<?php
function convert_to_table($line) {
return '<tr><td>'.str_replace("\t", '</td><td>', $line).'</td></tr>';
}
function tabfile_to_rows($file) {
return implode('', array_map('convert_to_table', file($file)));
}
echo '<table>'.tabfile_to_rows('test.txt').'</table>';
?>
3. How should it look like?
If the text file looks like this:
John Smith TAB The Blue Ocean TAB 992 TAB 91sd-155523-d TAB 11,84
Beverly Smith TAB Carrots are Bizarre TAB 211 TAB 555c-1js8ue-1 TAB 30,90
Carl Bonnen TAB Ridiculous CarrotsTAB 100 TAB aaaa-ya7ay8-1 TAB 28,99
Niki Storm TAB Bizarre Carrots Today TAB 1855 TAB 180a-000h6s-x TAB 199,99
Palm Dox TAB Minimods TAB 33 TAB x222-2121dd-0 TAB 6,00
and if I search for
CARROTS Bizarre
I should get
<TR><TD>Beverly Smith </TD><TD> Carrots are Bizarre </TD><TD> 211 </TD><TD> 555c-1js8ue-1 </TD><TD> 30,90</TD></TR>
<TR><TD>Carl Bonnen </TD><TD> Ridiculous Carrots</TD><TD> 100 </TD><TD> aaaa-ya7ay8-1 </TD><TD> 28,99 </TD></TR>
<TR><TD>Niki Storm </TD><TD> Bizarre Carrots Today </TD><TD> 1855 </TD><TD> 180a-000h6s-x </TD><TD> 199,99 </TD></TR>
Please, if you believe you can handle that - help me!!!
First of all, I should thank you in advance for reading this thread.
Please, help me if you can because it is urgent.
1. What do I want to do?
I wish to create a search <FORM> to search in the contents of a text file located somewhere on the server. I wish to be able to:
a) set a search criteria which is different from exact phrase
Example: Searching Blue monkey happy should find Happy blue monkey
b) set a search criteria with case INsensitive
Example: Searching HAPPY BlUe MonKeY should find Happy blue monkey
c) as the text file contains lines with a unique record on each; and on each line there are words separated by a TAB delimiter, I would like:
- if a part of the line in the file matches the search criteria, the WHOLE line has to be printed;
- results have to be printed in a <TABLE> with <TR> for every line match and <TD> for every word between the TAB delimiters in the file.
2. What have I done so far?
I got this code. It shows the contents of the text file in a table but all of them - not just the ones matching the search criteria...
<?php
function convert_to_table($line) {
return '<tr><td>'.str_replace("\t", '</td><td>', $line).'</td></tr>';
}
function tabfile_to_rows($file) {
return implode('', array_map('convert_to_table', file($file)));
}
echo '<table>'.tabfile_to_rows('test.txt').'</table>';
?>
3. How should it look like?
If the text file looks like this:
John Smith TAB The Blue Ocean TAB 992 TAB 91sd-155523-d TAB 11,84
Beverly Smith TAB Carrots are Bizarre TAB 211 TAB 555c-1js8ue-1 TAB 30,90
Carl Bonnen TAB Ridiculous CarrotsTAB 100 TAB aaaa-ya7ay8-1 TAB 28,99
Niki Storm TAB Bizarre Carrots Today TAB 1855 TAB 180a-000h6s-x TAB 199,99
Palm Dox TAB Minimods TAB 33 TAB x222-2121dd-0 TAB 6,00
and if I search for
CARROTS Bizarre
I should get
<TR><TD>Beverly Smith </TD><TD> Carrots are Bizarre </TD><TD> 211 </TD><TD> 555c-1js8ue-1 </TD><TD> 30,90</TD></TR>
<TR><TD>Carl Bonnen </TD><TD> Ridiculous Carrots</TD><TD> 100 </TD><TD> aaaa-ya7ay8-1 </TD><TD> 28,99 </TD></TR>
<TR><TD>Niki Storm </TD><TD> Bizarre Carrots Today </TD><TD> 1855 </TD><TD> 180a-000h6s-x </TD><TD> 199,99 </TD></TR>
Please, if you believe you can handle that - help me!!!