php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28517 differing behaviour between sscanf/ffscanf
Submitted: 2004-05-25 18:03 UTC Modified: 2004-12-15 09:42 UTC
From: dolfi at zkm dot de Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.9 OS: *
Private report: No CVE-ID: None
 [2004-05-25 18:03 UTC] dolfi at zkm dot de
Description:
------------
fscanf on multiline input works differently than sscanf on exactly the same data presented as a string.

Reproduce code:
---------------
<pre>
<?php
$str = "\n bla \nblup"; $file = "test.txt";
$fd = fopen($file, 'w'); fputs($fd, $str);
fclose($fd);
list($a,$b) = sscanf($str, ' %[a-z] %[a-z] ');
echo "$a;$b;\n";
$fd = fopen($file, 'r');
list($a,$b) = fscanf($fd, ' %[a-z] %[a-z] ');
fclose($fd);
echo "$a;$b;\n";
?>
</pre>


Expected result:
----------------
bla;blup;
bla;blup;


Actual result:
--------------
bla;blup;
;;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-15 09:42 UTC] sniper@php.net
It's because they're totally different functions.
fsscanf() reads file from descriptor. Your example only reads first line from the file, that being the \n char..

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC