0

Ok, Hi I need help.I making a project and need to find the end of file line of a file.I researched

file_get_contents

of a certain file and it worked but it did not register anything. And then found

feof

and used this:

<?php
 while (!feof($f)){}
?>

And it registers the previously appended code at the last of the file but prints the file as string. If you could help me write the function that will print only the eof line.

If you could help me, many thanks!! :D

2
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by NightLight
0

Hi, Warl30ck.
Ok, i will try to analiz your question.

need to find the end of file line

EOF it is not a line, it is a char. If you want get the last line in the file you can try code like this

// $fhedler = fopen('/path/to/file', 'r');
$str = '';
while ( $str = fgets($fhedler) );
// now $str contient last line of file

But this code so dirty.

0

Ok just tested. So then how would you print str?

<?php
$fhedler = fopen("hello.exe", "r");
$str = '';
while ( $str = fgets($fhedler) );

echo $str;
?>

Because It was not retuning anything!

Edited by Warl30ck: n/a

0

hello.exe - it is a binary file. fgets() - read stream while on found EOL char.

Check, if error reporting is turned.

Write you task, and mayble i will find more clear solution.

0

First I do not want to find EOF char in file to clear that up. The whole story is that I am trying to print on website, the appended[a] words on the binary file.

EDIT: Yes error reporting is on

Edited by Warl30ck: n/a

0

Unfortunately, my English so bad. I can`t clear understand what do you want.
Binary file is not best way to storing some text information. If you must do it, mayble it`ll better write programm on C and execute with some params.

0

Oh sorry I know but that's what I'm in need. and the webserver is linux so can't use binary programs on it.

Hey I will message you with clear understanding!!

0

Last message was pretty clear =)
Ok, if your hosting is not your own, i think you must write binary parser. Is your binary file exec. or simple binary(well structured)? It complex task and php realy bad in this way. Can you send sample of data and what response do you want in final?

0

I don't think you need file because I just appended data on random simple binary.

Final result: appended data on screen

Thankyou!

Edited by Warl30ck: n/a

0

Look, how i(or php, anyone) can read binary file without predefined structure?
can you say struct of one block. Like.
(char[20])(char[20])(int)(bool)
that equal in c

struct {
    char[20] first_name, last_name;
    int age;
    bool is_married;
};
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.