wrapper_functions.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. //
  3. // FPDI - Version 1.2
  4. //
  5. // Copyright 2004-2007 Setasign - Jan Slabon
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the "License");
  8. // you may not use this file except in compliance with the License.
  9. // You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS,
  15. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. // See the License for the specific language governing permissions and
  17. // limitations under the License.
  18. //
  19. if (!defined("PHP_VER_LOWER43"))
  20. define("PHP_VER_LOWER43", version_compare(PHP_VERSION, "4.3", "<"));
  21. /**
  22. * ensure that strspn works correct if php-version < 4.3
  23. */
  24. function _strspn($str1, $str2, $start=null, $length=null) {
  25. $numargs = func_num_args();
  26. if (PHP_VER_LOWER43 == 1) {
  27. if (isset($length)) {
  28. $str1 = substr($str1, $start, $length);
  29. } else {
  30. $str1 = substr($str1, $start);
  31. }
  32. }
  33. if ($numargs == 2 || PHP_VER_LOWER43 == 1) {
  34. return strspn($str1, $str2);
  35. } else if ($numargs == 3) {
  36. return strspn($str1, $str2, $start);
  37. } else {
  38. return strspn($str1, $str2, $start, $length);
  39. }
  40. }
  41. /**
  42. * ensure that strcspn works correct if php-version < 4.3
  43. */
  44. function _strcspn($str1, $str2, $start=null, $length=null) {
  45. $numargs = func_num_args();
  46. if (PHP_VER_LOWER43 == 1) {
  47. if (isset($length)) {
  48. $str1 = substr($str1, $start, $length);
  49. } else {
  50. $str1 = substr($str1, $start);
  51. }
  52. }
  53. if ($numargs == 2 || PHP_VER_LOWER43 == 1) {
  54. return strcspn($str1, $str2);
  55. } else if ($numargs == 3) {
  56. return strcspn($str1, $str2, $start);
  57. } else {
  58. return strcspn($str1, $str2, $start, $length);
  59. }
  60. }
  61. /**
  62. * ensure that fgets works correct if php-version < 4.3
  63. */
  64. function _fgets (&$h, $force=false) {
  65. $startpos = ftell($h);
  66. $s = fgets($h, 1024);
  67. if ((PHP_VER_LOWER43 == 1 || $force) && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
  68. $s = $ns[1];
  69. fseek($h,$startpos+strlen($s));
  70. }
  71. return $s;
  72. }
  73. ?>