Page 1 of 1

Searching in a text file

Posted: Sat Mar 28, 2009 5:39 pm
by r.gabor
Dear All,

I am using the following code to display what I have in the uploaded file.

$file = $_FILES['file']['name'];
$handle = @fopen($file, "r");
if ($handle) {
while (!feof($handle)) {
$line = fgets($handle, 4096);
print(strlen($line).' - '. $line.'<br />');
}
fclose($handle);
}

The problem I have is that the attached file, I can display , but cannot search in.

Even the lengt of the string are much longer that should be.

I would like to search each line for string.

I have try strpos, preg_match etc.. but no luck.

I have attached to this forum the file in question.

Can someone tell me, tha using this file how can I search for sting in a line and display the line if match found?

Many thanks.

Regards,
Gabor

Re: Searching in a text file

Posted: Sun Mar 29, 2009 4:34 am
by r.gabor
Is anyone there who can help on this?

Re: Searching in a text file

Posted: Sun Mar 29, 2009 4:42 am
by requinix
I'm too lazy to download a zip, open it up, and stick it in a text editor.
It's only 522 bytes - how about you post it in [syntax=php][/syntax] tags?

Re: Searching in a text file

Posted: Sun Mar 29, 2009 4:54 am
by r.gabor
Too lazy?

In this case why you even read the post?

I have the same file which is 3 mb, so I have attached a small part of the file.

I cannot copy past it as If I will open with any text editor, the text showing up just right.

If I open troug php, the file is readed in a strange format.

So that why. :)

Re: Searching in a text file

Posted: Sun Mar 29, 2009 10:50 am
by r.gabor
Ok, I ha the solution.

I have no idea of the file format, but if i convert every single line to ASCII, then convert the ASCII to char, then it is ok.

ereg or eregi or regex can be perform on it.