Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Filter / Digits.php
blob71905854e1c71564feb4b8dd9d21dba13b92b205
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Filter;
12 use Zend\Stdlib\StringUtils;
14 class Digits extends AbstractFilter
16 /**
17 * Defined by Zend\Filter\FilterInterface
19 * Returns the string $value, removing all but digit characters
21 * If the value provided is non-scalar, the value will remain unfiltered
22 * and an E_USER_WARNING will be raised indicating it's unfilterable.
24 * @param string $value
25 * @return string|mixed
27 public function filter($value)
29 if (null === $value) {
30 return null;
33 if (!is_scalar($value)) {
34 trigger_error(
35 sprintf(
36 '%s expects parameter to be scalar, "%s" given; cannot filter',
37 __METHOD__,
38 (is_object($value) ? get_class($value) : gettype($value))
40 E_USER_WARNING
42 return $value;
45 if (!StringUtils::hasPcreUnicodeSupport()) {
46 // POSIX named classes are not supported, use alternative 0-9 match
47 $pattern = '/[^0-9]/';
48 } elseif (extension_loaded('mbstring')) {
49 // Filter for the value with mbstring
50 $pattern = '/[^[:digit:]]/';
51 } else {
52 // Filter for the value without mbstring
53 $pattern = '/[\p{^N}]/';
56 return preg_replace($pattern, '', (string) $value);