php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47489 Bad scan conversion character "F" (non-locale aware scanning not possible)
Submitted: 2009-02-24 10:09 UTC Modified: 2011-04-08 20:37 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: erwin dot derksen at zonnet dot nl Assigned:
Status: Open Package: Strings related
PHP Version: 5.2.8 OS: Windows Vista
Private report: No CVE-ID: None
 [2009-02-24 10:09 UTC] erwin dot derksen at zonnet dot nl
Description:
------------
According to the documentation the format string is interpreted as described in the documentation for sprintf. However, function testSscanf() issues a warning 'Bad scan conversion character "F"'.

On further examination, it is not just a documentation error but an error in sscanf, see function testSscanf2()

Note that the dutch locale (nld) formats the decimal point as comma (,) and the thousand separator as a point (.).

Reproduce code:
---------------
function testSscanf()
{
	$f = null;
	$s = sprintf("%F", 1.34);
	$r = sscanf($s, "%F", $f);
	echo $f;
}

function testSscanf2()
{
	setlocale(LC_ALL, "nld");
	$f = 1.34;
	$s1 = sprintf("%f", $f);
	$s2 = sprintf("%F", $f);
	sscanf($s1, "%f", $f1);
	sscanf($s2, "%f", $f2);
	sscanf($s1, "%F", $f3);
	sscanf($s2, "%F", $f4);
	echo 's1 = ' . $s1 . "<br/>\n";
	echo 's2 = ' . $s2 . "<br/>\n";
	echo 'f = ' . $f . "<br/>\n";
	echo 'f1 = ' . $f1 . " (%f scanned from %f printed)<br/>\n";
	echo 'f2 = ' . $f2 . " (%f scanned from %F printed)<br/>\n";
	echo 'f3 = ' . $f3 . " (%F scanned from %f printed)<br/>\n";
	echo 'f4 = ' . $f4 . " (%F scanned from %F printed)<br/>\n";
}


Expected result:
----------------
1,34
1
1
1.34

Actual result:
--------------
s1 = 1,340000
s2 = 1.340000
f = 1,34
f1 = 1 (%f scanned from %f printed)
f2 = 1,34 (%f scanned from %F printed)
f3 = (%F scanned from %f printed)
f4 = (%F scanned from %F printed)



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-24 10:18 UTC] derick@php.net
I think this is just not implemented for scanning... as we use the standard libc functions for this. I'm marking this as a feature request.
 [2011-04-08 20:37 UTC] jani@php.net
-Package: Feature/Change Request +Package: Strings related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC