Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 1 | <?php |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 5.2.4 or newer |
| 6 | * |
| 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
| 19 | * @package CodeIgniter |
| 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
| 23 | * @link http://codeigniter.com |
| 24 | * @since Version 3.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
| 28 | |
| 29 | /** |
| 30 | * PHP ext/mbstring compatibility package |
| 31 | * |
| 32 | * @package CodeIgniter |
| 33 | * @subpackage CodeIgniter |
| 34 | * @category Compatibility |
| 35 | * @author Andrey Andreev |
| 36 | * @link http://codeigniter.com/user_guide/ |
| 37 | * @link http://php.net/mbstring |
| 38 | */ |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | |
| 42 | if (MB_ENABLED === TRUE) |
| 43 | { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // ------------------------------------------------------------------------ |
| 48 | |
| 49 | if ( ! function_exists('mb_strlen')) |
| 50 | { |
| 51 | /** |
| 52 | * mb_strlen() |
| 53 | * |
| 54 | * WARNING: This function WILL fall-back to strlen() |
| 55 | * if iconv is not available! |
| 56 | * |
| 57 | * @link http://php.net/mb_strlen |
| 58 | * @param string $str |
| 59 | * @param string $encoding |
| 60 | * @return string |
| 61 | */ |
| 62 | function mb_strlen($str, $encoding = NULL) |
| 63 | { |
| 64 | if (ICONV_ENABLED === TRUE) |
| 65 | { |
Andrey Andreev | fd6efad | 2014-04-29 01:00:42 +0300 | [diff] [blame^] | 66 | return iconv_strlen($str, isset($encoding) ? $encoding : config_item('charset')); |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | log_message('debug', 'Compatibility (mbstring): iconv_strlen() is not available, falling back to strlen().'); |
| 70 | return strlen($str); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // ------------------------------------------------------------------------ |
| 75 | |
| 76 | if ( ! function_exists('mb_strpos')) |
| 77 | { |
| 78 | /** |
| 79 | * mb_strpos() |
| 80 | * |
| 81 | * WARNING: This function WILL fall-back to strpos() |
| 82 | * if iconv is not available! |
| 83 | * |
| 84 | * @link http://php.net/mb_strpos() |
| 85 | * @param string $haystack |
| 86 | * @param string $needle |
| 87 | * @param int $offset |
| 88 | * @param string $encoding |
| 89 | * @return mixed |
| 90 | */ |
| 91 | function mb_strpos($haystack, $needle, $offset = 0, $encoding = NULL) |
| 92 | { |
| 93 | if (ICONV_ENABLED === TRUE) |
| 94 | { |
| 95 | return iconv_strpos($haystack, $needle, $offset, isset($encoding) ? $encoding : config_item('charset')); |
| 96 | } |
| 97 | |
| 98 | log_message('debug', 'Compatibility (mbstring): iconv_strpos() is not available, falling back to strpos().'); |
| 99 | return strpos($haystack, $needle, $offset); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // ------------------------------------------------------------------------ |
| 104 | |
| 105 | if ( ! function_exists('mb_substr')) |
| 106 | { |
| 107 | /** |
| 108 | * mb_substr() |
| 109 | * |
| 110 | * WARNING: This function WILL fall-back to substr() |
| 111 | * if iconv is not available. |
| 112 | * |
| 113 | * @link http://php.net/mb_substr |
| 114 | * @param string $str |
| 115 | * @param int $start |
| 116 | * @param int $length |
| 117 | * @param string $encoding |
| 118 | * @return string |
| 119 | */ |
| 120 | function mb_substr($str, $start, $length = NULL, $encoding = NULL) |
| 121 | { |
| 122 | if (ICONV_ENABLED === TRUE) |
| 123 | { |
| 124 | isset($encoding) OR $encoding = config_item('charset'); |
| 125 | return iconv_substr( |
| 126 | $str, |
| 127 | $start, |
| 128 | isset($length) ? $length : iconv_strlen($str, $encoding), // NULL doesn't work |
| 129 | $encoding |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | log_message('debug', 'Compatibility (mbstring): iconv_substr() is not available, falling back to substr().'); |
| 134 | return isset($length) |
| 135 | ? substr($str, $start, $length) |
| 136 | : substr($str, $start); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* End of file mbstring.php */ |
| 141 | /* Location: ./system/core/compat/mbstring.php */ |