Example #1
0
function fCharlen($str, $start, $len, $dot = " ...")
{
    $str = trim(ltrim($str));
    $strlennum = strlen($str);
    if ($len > $strlennum) {
        $len = $strlennum;
    }
    $endsub = substr($str, $len - 1, $len);
    $endstr = array("`", "~", "@", "#", "^", ".", "&", "*", "(", "<", "《", "-", "_", "+", "=", "|", "{", "“", "[", "/", "\\", " ", ",", ";", "—");
    if (in_array($endsub, $endstr)) {
        $len = $len - 1;
    }
    if ($start > $strlennum) {
        $start = 0;
    }
    if ($start >= 0) {
        for ($i = 0; $i < $len; $i++) {
            if (ord(substr($str, $start + $i, 1)) >= 0xa0 or ord(substr($str, $i, 1)) >= 0x81 or ord(substr($str, $i, 1)) >= 0xa1) {
                $str_chr .= substr($str, $start + $i, 2);
                $i++;
            } else {
                $str_chr .= substr($str, $start + $i, 1);
            }
        }
    } else {
        if ($start < -$strlennum) {
            $start = 0;
        } else {
            $len = $len + $start;
        }
        for ($i = 1; $i <= $len; $i++) {
            if (ord(substr($str, $start - $i, 1)) >= 0xa0 or ord(substr($str, $start - $i, 1)) >= 0x81 or ord(substr($str, $start - $i, 1)) >= 0xa1) {
                $str_chr .= substr($str, $start - $i, 2);
                $i++;
            } else {
                $str_chr .= substr($str, $start - $i, 1);
            }
        }
    }
    $str_chr = fCharchr($str_chr);
    return $str_chr . $dot;
}
Example #2
0
function Add_d(&$array)
{
    global $config;
    if (is_array($array)) {
        foreach ($array as $key => $value) {
            if (!is_array($value)) {
                if ($value == ' ') {
                    $array[$key] = "";
                }
                if ($config['html'] == '1') {
                    $array[$key] = fCharchr($value);
                } else {
                    $array[$key] = fShowhtml(trim(ltrim($value)));
                }
            } else {
                Add_d($array[$key]);
            }
        }
    } else {
        if ($array == ' ') {
            $array = "";
        }
        if ($config['html'] == '1') {
            $array = fCharchr($array);
        } else {
            $array = fShowhtml(trim(ltrim($array)));
        }
    }
}