mb_split替换导致模块被禁用

时间:2016-04-01 15:51:25

标签: php mbstring

我的托管无法启用mbstring模块,如何替换这段代码?替换mb_split? 这不是我的代码,我只想解决这个问题。

我的目标是使用preg_replace或其他没有mb_split

的函数
 /**
     * @param      $content
     * @param bool $amount
     *
     * @return mixed
     */
public function truncate($content, $amount = false)
{

    if (!$amount || preg_match_all("/\s+/", $content, $junk) <= $amount) return $content;

    $content = preg_replace_callback("/(<\/?[^>]+\s+[^>]*>)/", array($this, '_shield'), $content);

    $words   = 0;
    $output  = array();
    $content = str_replace(array("<", ">"), array(" <", "> "), $content);
    $tokens  = mb_split("\s+", $content);

    foreach ($tokens as $token) {
        // goes through tags and store them so they can get restored afterwards
        if (preg_match_all("/<(\/?[^\x01>]+)([^>]*)>/", $token, $tags, PREG_SET_ORDER)) {
            foreach ($tags as $tag) $this->_recordTag($tag[1], $tag[2]);
        }

        $output[] = trim($token);

        if (!preg_match("/^(<[^>]+>)+$/", $token)) {
            // if it's a real word outside tags, increase the count
            if (preg_match("/\p{L}+/u", $token)) $matching = true;
            else $matching = preg_match("/\w/", $token);

            if (!strpos($token, '=') && !strpos($token, '<') && strlen(trim(strip_tags($token))) > 0 && $matching) ++$words;
        }

        if ($words >= $amount) break;
    }

    $truncate = $this->_unshield(implode(' ', $output));

    return $truncate;
}

0 个答案:

没有答案