|
1 <?php |
|
2 |
|
3 /** |
|
4 * Zend Framework |
|
5 * |
|
6 * LICENSE |
|
7 * |
|
8 * This source file is subject to the new BSD license that is bundled |
|
9 * with this package in the file LICENSE.txt. |
|
10 * It is also available through the world-wide-web at this URL: |
|
11 * http://framework.zend.com/license/new-bsd |
|
12 * If you did not receive a copy of the license and are unable to |
|
13 * obtain it through the world-wide-web, please send an email |
|
14 * to license@zend.com so we can send you a copy immediately. |
|
15 * |
|
16 * @category Zend |
|
17 * @package Zend_Filter |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Digits.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * @see Zend_Filter_Interface |
|
26 */ |
|
27 require_once 'Zend/Filter/Interface.php'; |
|
28 |
|
29 |
|
30 /** |
|
31 * @category Zend |
|
32 * @package Zend_Filter |
|
33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
35 */ |
|
36 class Zend_Filter_Digits implements Zend_Filter_Interface |
|
37 { |
|
38 /** |
|
39 * Is PCRE is compiled with UTF-8 and Unicode support |
|
40 * |
|
41 * @var mixed |
|
42 **/ |
|
43 protected static $_unicodeEnabled; |
|
44 |
|
45 /** |
|
46 * Class constructor |
|
47 * |
|
48 * Checks if PCRE is compiled with UTF-8 and Unicode support |
|
49 * |
|
50 * @return void |
|
51 */ |
|
52 public function __construct() |
|
53 { |
|
54 if (null === self::$_unicodeEnabled) { |
|
55 self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; |
|
56 } |
|
57 } |
|
58 |
|
59 /** |
|
60 * Defined by Zend_Filter_Interface |
|
61 * |
|
62 * Returns the string $value, removing all but digit characters |
|
63 * |
|
64 * @param string $value |
|
65 * @return string |
|
66 */ |
|
67 public function filter($value) |
|
68 { |
|
69 if (!self::$_unicodeEnabled) { |
|
70 // POSIX named classes are not supported, use alternative 0-9 match |
|
71 $pattern = '/[^0-9]/'; |
|
72 } else if (extension_loaded('mbstring')) { |
|
73 // Filter for the value with mbstring |
|
74 $pattern = '/[^[:digit:]]/'; |
|
75 } else { |
|
76 // Filter for the value without mbstring |
|
77 $pattern = '/[\p{^N}]/'; |
|
78 } |
|
79 |
|
80 return preg_replace($pattern, '', (string) $value); |
|
81 } |
|
82 } |