| 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 | |
|---|
| 20 | |
|---|
| 21 | if (!defined("PHP_VER_LOWER43")) |
|---|
| 22 | define("PHP_VER_LOWER43", version_compare(PHP_VERSION, "4.3", "<")); |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * ensure that strspn works correct if php-version < 4.3 |
|---|
| 27 | */ |
|---|
| 28 | function _strspn($str1, $str2, $start=null, $length=null) { |
|---|
| 29 | $numargs = func_num_args(); |
|---|
| 30 | |
|---|
| 31 | if (PHP_VER_LOWER43 == 1) { |
|---|
| 32 | if (isset($length)) { |
|---|
| 33 | $str1 = substr($str1, $start, $length); |
|---|
| 34 | } else { |
|---|
| 35 | $str1 = substr($str1, $start); |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | if ($numargs == 2 || PHP_VER_LOWER43 == 1) { |
|---|
| 40 | return strspn($str1, $str2); |
|---|
| 41 | } else if ($numargs == 3) { |
|---|
| 42 | return strspn($str1, $str2, $start); |
|---|
| 43 | } else { |
|---|
| 44 | return strspn($str1, $str2, $start, $length); |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * ensure that strcspn works correct if php-version < 4.3 |
|---|
| 51 | */ |
|---|
| 52 | function _strcspn($str1, $str2, $start=null, $length=null) { |
|---|
| 53 | $numargs = func_num_args(); |
|---|
| 54 | |
|---|
| 55 | if (PHP_VER_LOWER43 == 1) { |
|---|
| 56 | if (isset($length)) { |
|---|
| 57 | $str1 = substr($str1, $start, $length); |
|---|
| 58 | } else { |
|---|
| 59 | $str1 = substr($str1, $start); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | if ($numargs == 2 || PHP_VER_LOWER43 == 1) { |
|---|
| 64 | return strcspn($str1, $str2); |
|---|
| 65 | } else if ($numargs == 3) { |
|---|
| 66 | return strcspn($str1, $str2, $start); |
|---|
| 67 | } else { |
|---|
| 68 | return strcspn($str1, $str2, $start, $length); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * ensure that fgets works correct if php-version < 4.3 |
|---|
| 75 | */ |
|---|
| 76 | function _fgets (&$h, $force=false) { |
|---|
| 77 | $startpos = ftell($h); |
|---|
| 78 | $s = fgets($h, 1024); |
|---|
| 79 | |
|---|
| 80 | if ((PHP_VER_LOWER43 == 1 || $force) && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) { |
|---|
| 81 | $s = $ns[1]; |
|---|
| 82 | fseek($h,$startpos+strlen($s)); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | return $s; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | ?> |
|---|