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

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.

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!

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.

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

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.

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!!

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?

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

Final result: appended data on screen

Thankyou!

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;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.