FloatFromString.php 546 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

namespace Application\Filter;

use Zend\Filter\AbstractFilter;

class FloatFromString extends AbstractFilter
{
    private static $instance;


    public function filter($value)
    {
        $value = preg_replace("/[^0-9,\.-]/","",$value);
        $value = str_replace(',','.',$value);
        $value = floatval($value);

        return $value;
    }



    public static function run( $value )
    {
        if (!self::$instance){
            self::$instance = new self;
        }

        return self::$instance->filter($value);
    }
}