在 OpenCart 中,Daniel 包含一个带有各种 UTF8 函数的 UTF8 帮助文件。
这是我的问题...
在原生 php 函数中包装 utf8 解码的代码段与在 OpenCart 中使用 utf8 辅助函数有什么区别(我找不到)?
例如在 OpenCart 验证领域,我们看到很多这样的:
if (utf8_strlen($this->request->post['myvalue']) < 3)
这与以下内容完全相同:
if (strlen(utf8_decode($this->request->post['myvalue'])) < 3)
文件中还有额外的帮助函数utf8_strtolower,utf8_strpos等等。
为什么不简单地使用:
strtolower (utf8_decode($myvariable))
只是好奇,因为我正在构建一个基于 OpenCart MVC 的新 CMS 框架。
编辑:添加新mb_课程。
这是mb_函数的新类,请检查是否有任何错误。
final class Tester {
    public function _strlen ($string) {
        return mb_strlen ($string, mb_detect_encoding($string));
    }
    public function _strpos ($string, $needle, $offset = false) {
        if (!$offset):
            $data = explode ($needle, $string, 2);
            if (count ($data) > 1):
                $offset = $this->_strlen ($data[0]);
            endif;
        endif;
        return mb_strpos ($string, $needle, $offset, mb_detect_encoding ($string));
    }
    public function _strrpos ($string, $needle, $offset = false) {
        if (!$offset):
            $data = explode ($needle, $string);
            if (count ($data) > 1):
                array_pop ($data);
                $string = join ($needle, $data);
                $offset = $this->_strlen ($string);
            endif;
        endif;
        return mb_strrpos ($string, $needle, $offset, mb_detect_encoding ($string));
    }
    public function _substr ($string, $start, $length = false) {
        if (!$length):
            $length = $this->_strlen ($string);
        endif;
        return mb_substr ($string, $start, $length, mb_detect_encoding ($string));
    }
    public function _strtolower ($string) {
        return mb_strtolower ($string, mb_detect_encoding ($string));
    }
    public function _strtoupper ($string) {
        return mb_strtoupper ($string, mb_detect_encoding ($string));
    }
    public function _array ($data, $exit = true) {
        echo "<pre>";
        print_r ($data);
        echo "</pre>";
        if ($exit):
            exit;
        endif;
    }
}
这还包括我之前在加载器类中拥有的数组测试功能。