Forum Moderators: coopster

Message Too Old, No Replies

How to search a specific quote in a text file..?

i want to search for a specific line in a text file

         

umair

12:54 pm on Jun 24, 2003 (gmt 0)

10+ Year Member



i had a search script (cgi) which can be used to search for a Quote that contains a SPECIFIC word. the quotes was seperated by # in text file, any idea how to search that text file using PHP. i m very new to php, so it will be better if u write a small (complete) script instead of giving logics, THANKS

jaski

1:47 pm on Jun 24, 2003 (gmt 0)

10+ Year Member



Hi Umair,
Welcome to the Webmaster World.

I am not sure if I have understood your problem well enough to give you a complete script.

but ereg() is a function to match strings in PHP.

vincevincevince

11:36 pm on Jun 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$word = "foo";
$source = fopen("thefile.txt", "r");
$repeated = fread($source, fileSize("thefile.txt"));
fclose($source);
preg_match("/#[^#]*$word[^#]*/",$source,$result);
echo $result[0];

now ya owe me :-p j\k!

umair

11:41 am on Jul 5, 2003 (gmt 0)

10+ Year Member



upon using above code, i m receiving error,

"Parse error: parse error, unexpected T_VARIABLE in /home/virtual/site39/fst/home/eislam/public_html/search/search.php on line 2"

i made a little changes in code,
<? php
$source = fopen("datafile.txt", "r");
$repeated = fread($source, fileSize("datafile.txt"));
fclose($source);
preg_match("/#[^#]*$word[^#]*/",$source,$result);
echo $result[0];
?>
and using the url like this,
[mysite.com...]

vincevincevince

1:31 pm on Jul 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<?php
$word = $_REQUEST['word'];
$source = fopen("datafile.txt", "r");
$repeated = fread($source, fileSize("datafile.txt"));
fclose($source);
preg_match("/#[^#]*".$word."[^#]*/",$repeated,$result);
echo substr($result[0],1);
?>

Your error: a space between <? and php "<? php"
My error 1: search was within $source not $repeated
My error 2: forgot to remove the leading # from the output

Let me know if you still have problems

umair

8:51 am on Jul 9, 2003 (gmt 0)

10+ Year Member



ya it works, Thanks, but it picks only one line randomly from the file, while i want to display all the matching results. And some times it does not display the result even when the key word exists Because it returns a CaseSenSitIvE Search result.