PageRenderTime 41ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Zend/Filter/Digits.php

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