Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 1 | <?php |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 8 | * |
Master Yoda | da60e9b | 2016-12-31 08:46:18 -0800 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2017, British Columbia Institute of Technology |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Master Yoda | da60e9b | 2016-12-31 08:46:18 -0800 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 3.0.0 |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
| 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
| 39 | |
| 40 | /** |
| 41 | * PHP ext/mbstring compatibility package |
| 42 | * |
| 43 | * @package CodeIgniter |
| 44 | * @subpackage CodeIgniter |
| 45 | * @category Compatibility |
| 46 | * @author Andrey Andreev |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 47 | * @link https://codeigniter.com/user_guide/ |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 48 | * @link http://php.net/mbstring |
| 49 | */ |
| 50 | |
| 51 | // ------------------------------------------------------------------------ |
| 52 | |
| 53 | if (MB_ENABLED === TRUE) |
| 54 | { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // ------------------------------------------------------------------------ |
| 59 | |
| 60 | if ( ! function_exists('mb_strlen')) |
| 61 | { |
| 62 | /** |
| 63 | * mb_strlen() |
| 64 | * |
| 65 | * WARNING: This function WILL fall-back to strlen() |
| 66 | * if iconv is not available! |
| 67 | * |
| 68 | * @link http://php.net/mb_strlen |
| 69 | * @param string $str |
| 70 | * @param string $encoding |
Andrey Andreev | ee9d428 | 2017-06-05 10:44:37 +0300 | [diff] [blame^] | 71 | * @return int |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 72 | */ |
| 73 | function mb_strlen($str, $encoding = NULL) |
| 74 | { |
| 75 | if (ICONV_ENABLED === TRUE) |
| 76 | { |
Andrey Andreev | fd6efad | 2014-04-29 01:00:42 +0300 | [diff] [blame] | 77 | return iconv_strlen($str, isset($encoding) ? $encoding : config_item('charset')); |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | log_message('debug', 'Compatibility (mbstring): iconv_strlen() is not available, falling back to strlen().'); |
| 81 | return strlen($str); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // ------------------------------------------------------------------------ |
| 86 | |
| 87 | if ( ! function_exists('mb_strpos')) |
| 88 | { |
| 89 | /** |
| 90 | * mb_strpos() |
| 91 | * |
| 92 | * WARNING: This function WILL fall-back to strpos() |
| 93 | * if iconv is not available! |
| 94 | * |
bjjay | b6d1746 | 2015-03-12 10:31:14 +0800 | [diff] [blame] | 95 | * @link http://php.net/mb_strpos |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 96 | * @param string $haystack |
| 97 | * @param string $needle |
| 98 | * @param int $offset |
| 99 | * @param string $encoding |
| 100 | * @return mixed |
| 101 | */ |
| 102 | function mb_strpos($haystack, $needle, $offset = 0, $encoding = NULL) |
| 103 | { |
| 104 | if (ICONV_ENABLED === TRUE) |
| 105 | { |
| 106 | return iconv_strpos($haystack, $needle, $offset, isset($encoding) ? $encoding : config_item('charset')); |
| 107 | } |
| 108 | |
| 109 | log_message('debug', 'Compatibility (mbstring): iconv_strpos() is not available, falling back to strpos().'); |
| 110 | return strpos($haystack, $needle, $offset); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // ------------------------------------------------------------------------ |
| 115 | |
| 116 | if ( ! function_exists('mb_substr')) |
| 117 | { |
| 118 | /** |
| 119 | * mb_substr() |
| 120 | * |
| 121 | * WARNING: This function WILL fall-back to substr() |
| 122 | * if iconv is not available. |
| 123 | * |
| 124 | * @link http://php.net/mb_substr |
| 125 | * @param string $str |
| 126 | * @param int $start |
| 127 | * @param int $length |
| 128 | * @param string $encoding |
| 129 | * @return string |
| 130 | */ |
| 131 | function mb_substr($str, $start, $length = NULL, $encoding = NULL) |
| 132 | { |
| 133 | if (ICONV_ENABLED === TRUE) |
| 134 | { |
| 135 | isset($encoding) OR $encoding = config_item('charset'); |
| 136 | return iconv_substr( |
| 137 | $str, |
| 138 | $start, |
| 139 | isset($length) ? $length : iconv_strlen($str, $encoding), // NULL doesn't work |
| 140 | $encoding |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | log_message('debug', 'Compatibility (mbstring): iconv_substr() is not available, falling back to substr().'); |
| 145 | return isset($length) |
| 146 | ? substr($str, $start, $length) |
| 147 | : substr($str, $start); |
| 148 | } |
| 149 | } |