Searching in a text file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
r.gabor
Forum Newbie
Posts: 4
Joined: Sat Mar 28, 2009 5:16 pm

Searching in a text file

Post 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
Attachments
log.zip
(522 Bytes) Downloaded 2 times
r.gabor
Forum Newbie
Posts: 4
Joined: Sat Mar 28, 2009 5:16 pm

Re: Searching in a text file

Post by r.gabor »

Is anyone there who can help on this?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Searching in a text file

Post 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?
r.gabor
Forum Newbie
Posts: 4
Joined: Sat Mar 28, 2009 5:16 pm

Re: Searching in a text file

Post 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. :)
r.gabor
Forum Newbie
Posts: 4
Joined: Sat Mar 28, 2009 5:16 pm

Re: Searching in a text file

Post 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.
Post Reply