Bug #67748 [Fbk->NoF]: fscanf does not work when reading text file with only one character
| From: | ab@php.net | Date: | Mon, 06 Oct 2014 16:18:39 +0000 |
| Subject: | Bug #67748 [Fbk->NoF]: fscanf does not work when reading text file with only one character | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187891@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67748&edit=1
ID: 67748
Updated by: ab@php.net
Reported by: tr_77019 at yahoo dot com
Summary: fscanf does not work when reading text file with
only one character
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Unknown/Other Function
Operating System: Windows
PHP Version: 5.3.28
Block user comment: N
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2014-08-13 13:36:43] ab@php.net
I can't reproduce this, running this
$fd = fopen('numbers.txt', 'r');
var_dump(fscanf($fd, '%d'));
and using a file with one number per line.
Could you try to remove the newline check from the format, and pls check the new lines in the file.
Thanks.
------------------------------------------------------------------------
[2014-08-02 14:41:38] tr_77019 at yahoo dot com
Description:
------------
fscanf does not read the first line of a text file when there is only one integer on each line.
However, it does work for characters and strings.
Test script:
---------------
<?php
$fp = fopen("numbers.txt", "r");
while ($num = fscanf($fp, "%d\n")) {
list($newnum) = $num;
echo "This is $newnum<br>";
}
fclose($fp);
?>
numbers.txt contains:
1
2
3
4
It works for characters and strings:
<?php
$fp = fopen("names.txt", "r");
while ($name = fscanf($fp, "%s\n")) {
list($newname) = $name;
echo "This is $newname<br>";
}
fclose($fp);
?>
names.txt contains:
javier
hiroshi
robert
luigi
or:
a
b
c
d
Expected result:
----------------
This is 1
This is 2
This is 3
This is 4
This is javier
This is hiroshi
This is robert
This is luigi
This is a
This is b
This is c
This is d
Actual result:
--------------
This is
This is 2
This is 3
This is 4
This is javier
This is hiroshi
This is robert
This is luigi
This is a
This is b
This is c
This is d
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67748&edit=1