php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #46267 mismatch between sscanf and localeconv
Submitted: 2008-10-10 00:40 UTC Modified: 2009-11-20 13:14 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: oswald at jaskolla dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-10-10 00:40 UTC] oswald at jaskolla dot net
Description:
------------
sscanf() seems not to be locale-aware when interpreting '%f', even though the documentation says it is. localeconv() says that after my call to setlocale(), the comma is interpreted as decimal separator. Still everything after the comma is omitted.

Tested environments:
Windows XP, PHP 5.2.5, Apache 2.2.8 (mpm_winnt)
Linux 2.6.9, PHP 5.2.6RC1, Apache 2.2.8 (prefork)

Reproduce code:
---------------
setlocale(LC_ALL, array('de_DE.utf-8', 'german'));
$value = sscanf('3,14159265', '%f');
echo '<div>parsed: &pi; &asymp;', $value[0], '</div>';
echo '<div>formatted: &pi; &asymp;'; printf('%f', 3.14159265); echo '</div>';


Expected result:
----------------
parsed: &#960; &#8776;3.14159265
formatted: &#960; &#8776;3,14159265

Actual result:
--------------
parsed: &#960; &#8776;3
formatted: &#960; &#8776;3,14159265


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-10 00:43 UTC] oswald at jaskolla dot net
Description:
------------
sscanf() seems not to be locale-aware when interpreting '%f', even
though the documentation says it is. localeconv() says that after my
call to setlocale(), the comma is interpreted as decimal separator.
Still everything after the comma is omitted.

Tested environments:
Windows XP, PHP 5.2.5, Apache 2.2.8 (mpm_winnt)
Linux 2.6.9, PHP 5.2.6RC1, Apache 2.2.8 (prefork)

Reproduce code:
---------------
setlocale(LC_ALL, array('de_DE.utf-8', 'german'));
$value = sscanf('3,14159265', '%f');
echo '<div>parsed: &pi; &asymp; ', $value[0], '</div>';
echo '<div>formatted: &pi; &asymp; '; printf('%f', 3.14159265); echo
'</div>';

Expected result:
----------------
parsed: &#960; &#8776; 3.14159265
formatted: &#960; &#8776; 3,14159265

Actual result:
--------------
parsed: &#960; &#8776; 3
formatted: &#960; &#8776; 3,14159265
 [2008-10-10 00:53 UTC] oswald at jaskolla dot net
I am sorry for seeming to spam this bug report. The "Edit Submission" tab made me think I could edit my actual submission without posting a comment. My guess was that this was the idea behind requiring me to enter the password. Obviously I was wrong and like to apologize.

My actual intention of editing the submission was, to turn &#960; into the greek letter that designates the ration between the diameter and the area of a circle and to turn &#8776; into the symbol that usually designates similarity (something is messed up somewhere on the road: my clipboard -> my browser -> your web application -> your database -> your web application -> my browser).
 [2008-10-10 06:33 UTC] juwe at clasennet dot de
This problem goes a little deeper than sscanf/fscanf not being locale-aware:

While sprintf & co support the modifiers F,G and b, sscanf and fscanf do not. Furthermore sscanf/fscanf understand the modifiers D,i and n, while sprintf & co clearly do not.

Unfortunately the documentation for sscanf/fscanf refers to the documentation of sprintf for an explanation of the syntax for it's format argument. 

IMHO this is mostly a documentation problem, but it would be nice for both types of function to accept the same format syntax (as much as possible given the different focus)
 [2009-11-20 13:14 UTC] svn@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=291079
Log: Document sprintf differences (bug #46267)
 [2009-11-20 13:14 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 14:01:29 2024 UTC