Greetings. Tell please function PHP5 which defines presence of the end of a line (like !feof - for the file end).
Thanks in advance!)

6 Years
Discussion Span
Last Post by vedro-compota

Can you please describe your use case a little more so we have a better idea of what you are trying to accomplish?

You can read through a file line by line using fgets, but if you are trying to detect if a character is an end of line character, which varies (\n \r\n etc.), you would use something like fseek to progress the file pointer 1 character at a time and fread to capture the next byte and test it for being an EOL character.

Votes + Comments

Yes. I want to read the file from character to character, amassing read in a variable of type string. Once I find the new line character - uses this variable in a mysql_query function.
Thanks to your response, I think it's possible to do so -

$fdata = fopen ($filename, "r+");
$str = '';	 
while (!feof($fdata))
  $simb = fgetc($fdata);
  if  ($simb = '/n')
    $str = $str + $simb;
	$str = '';
   str = $str + $simb;

but it is not clear - why are so many options -

\n \r\n

for example new string in Delphi is uniquely denoted by -


Edited by vedro-compota: n/a


It sounds like you're trying to read through a file line by line and then use the value of that line to perform a query.

Personally I prefer the SplFileObject assuming you're using php > 5.1.0

//Create SplFileObject instance of $filename
$file = new SplFileObject($filename);

//Set the drop new line flag so returned line value does not include \n etc.

//Foreach line in the file execute a query
foreach ($file as $line) {

I continue this thread.Are these lines equivalent? -

1)echo ($str."\r\n");
 2)echo ($str."<br>");

(Judging by the script - no)
Tell me please, what is my mistake?

Edited by vedro-compota: n/a

This question has already been answered. 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.