Bug #67748 [NEW]: fscanf does not work when reading text file with only one character

From: Date: Sat, 02 Aug 2014 14:41:39 +0000
Subject: Bug #67748 [NEW]: fscanf does not work when reading text file with only one character
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186944@lists.php.net to get a copy of this message
From: tr_77019 at yahoo dot com Operating system: Windows PHP version: 5.3.28 Package: Unknown/Other Function Bug Type: Bug Bug description:fscanf does not work when reading text file with only one character 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 bug report at https://bugs.php.net/bug.php?id=67748&edit=1 --

« previous php.bugs (#186944) next »