php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #43097 Filters are removing more characters than they should
Submitted: 2007-10-24 16:40 UTC Modified: 2007-11-21 14:32 UTC
From: john_judy at homedecorators dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.4 OS: FreeBSD and Windows XP SP2
Private report: No CVE-ID: None
 [2007-10-24 16:40 UTC] john_judy at homedecorators dot com
Description:
------------
When running the filters FILTER_SANITIZE_NUMBER_INT or FILTER_SANITIZE_NUMBER_FLOAT, decimal points are being removed.

The filter information from phpinfo() (run on our FreeBSD machine which still has 5.2.3, although this bug happens on PHP version 5.2.4 in Windows XP also) is as follows:

filter
Input Validation and Filtering 	enabled
Revision 	$Revision: 1.74 $

Directive	Local Value	Master Value
filter.default	unsafe_raw	unsafe_raw
filter.default_flags	no value	no value

Reproduce code:
---------------
<?php
$test = "456.78";
echo $test."\n";
echo filter_var($test,FILTER_SANITIZE_NUMBER_INT)."\n";
echo filter_var($test,FILTER_SANITIZE_NUMBER_FLOAT,
array(FILTER_FLAG_ALLOW_FRACTION))."\n";
?>


Expected result:
----------------
456.78
456.78
456.78

Actual result:
--------------
456.78
45678
45678

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-25 12:03 UTC] jani@php.net
From the friendly manual:
"
options

Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. For the "callback" filter, callback type should be passed. 
"

echo filter_var($test,FILTER_SANITIZE_NUMBER_FLOAT,
array("flags" => FILTER_FLAG_ALLOW_FRACTION))."\n";

And about FILTER_SANITIZE_NUMBER_INT:
"Remove all characters except digits and +-."
(the dot in that sentence is NOT the decimal dot!)

 [2007-10-25 16:51 UTC] jani@php.net
The docs need some work on these. Using dots where it might mean something else is not good idea. And some stuff isn't even documented.
f.e. the array parameter.
 [2007-11-21 14:32 UTC] vrana@php.net
Plus and minus signs are printed in monospace in opossit to fullstop. However I changed them to words.

Array is documented by filter_var(): "Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 01 13:00:03 2025 UTC