mb_substr

The timeline below displays how wordpress function mb_substr has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 3.7

function mb_substr($str, $start, $len = '', $encoding = "UTF-8")
{
    $limit = strlen($str);
    for ($s = 0; $start > 0; --$start) {
        // found the real start
        if ($s >= $limit) {
            break;
        }
        if ($str[$s] <= "") {
            ++$s;
        } else {
            ++$s;
            // skip length
            while ($str[$s] >= "\x80" && $str[$s] <= "\xbf") {
                ++$s;
            }
        }
    }
    if ($len == '') {
        return substr($str, $s);
    } else {
        for ($e = $s; $len > 0; --$len) {
            //found the real end
            if ($e >= $limit) {
                break;
            }
            if ($str[$e] <= "") {
                ++$e;
            } else {
                ++$e;
                //skip length
                while ($str[$e] >= "\x80" && $str[$e] <= "\xbf" && $e < $limit) {
                    ++$e;
                }
            }
        }
    }
    return substr($str, $s, $e - $s);
}