compatibility.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * compatibility functions
  4. *
  5. * This file contains a few functions that might be missing from the PHP build
  6. */
  7. if(!function_exists('ctype_space')) {
  8. /**
  9. * Check for whitespace character(s)
  10. *
  11. * @see ctype_space
  12. * @param string $text
  13. * @return bool
  14. */
  15. function ctype_space($text) {
  16. if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
  17. if(trim($text) === '') return true;
  18. return false;
  19. }
  20. }
  21. if(!function_exists('ctype_digit')) {
  22. /**
  23. * Check for numeric character(s)
  24. *
  25. * @see ctype_digit
  26. * @param string $text
  27. * @return bool
  28. */
  29. function ctype_digit($text) {
  30. if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
  31. if(preg_match('/^\d+$/', $text)) return true;
  32. return false;
  33. }
  34. }
  35. if(!function_exists('gzopen') && function_exists('gzopen64')) {
  36. /**
  37. * work around for PHP compiled against certain zlib versions #865
  38. *
  39. * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
  40. *
  41. * @param string $filename
  42. * @param string $mode
  43. * @param int $use_include_path
  44. * @return mixed
  45. */
  46. function gzopen($filename, $mode, $use_include_path = 0) {
  47. return gzopen64($filename, $mode, $use_include_path);
  48. }
  49. }
  50. if(!function_exists('gzseek') && function_exists('gzseek64')) {
  51. /**
  52. * work around for PHP compiled against certain zlib versions #865
  53. *
  54. * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
  55. *
  56. * @param resource $zp
  57. * @param int $offset
  58. * @param int $whence
  59. * @return int
  60. */
  61. function gzseek($zp, $offset, $whence = SEEK_SET) {
  62. return gzseek64($zp, $offset, $whence);
  63. }
  64. }
  65. if(!function_exists('gztell') && function_exists('gztell64')) {
  66. /**
  67. * work around for PHP compiled against certain zlib versions #865
  68. *
  69. * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
  70. *
  71. * @param resource $zp
  72. * @return int
  73. */
  74. function gztell($zp) {
  75. return gztell64($zp);
  76. }
  77. }