| 68 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* CodeIgniter
|
|
|
4 |
*
|
|
|
5 |
* An open source application development framework for PHP
|
|
|
6 |
*
|
|
|
7 |
* This content is released under the MIT License (MIT)
|
|
|
8 |
*
|
| 2414 |
lars |
9 |
* Copyright (c) 2014 - 2019, British Columbia Institute of Technology
|
| 68 |
lars |
10 |
*
|
|
|
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:
|
|
|
17 |
*
|
|
|
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
|
|
|
31 |
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
| 2414 |
lars |
32 |
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
|
|
33 |
* @license https://opensource.org/licenses/MIT MIT License
|
| 68 |
lars |
34 |
* @link https://codeigniter.com
|
|
|
35 |
* @since Version 3.0.0
|
|
|
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
|
|
|
47 |
* @link https://codeigniter.com/user_guide/
|
|
|
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
|
| 2107 |
lars |
71 |
* @return int
|
| 68 |
lars |
72 |
*/
|
|
|
73 |
function mb_strlen($str, $encoding = NULL)
|
|
|
74 |
{
|
|
|
75 |
if (ICONV_ENABLED === TRUE)
|
|
|
76 |
{
|
|
|
77 |
return iconv_strlen($str, isset($encoding) ? $encoding : config_item('charset'));
|
|
|
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 |
*
|
|
|
95 |
* @link http://php.net/mb_strpos
|
|
|
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 |
}
|