PHP function substr() error

后端 未结 7 2020
攒了一身酷
攒了一身酷 2020-12-29 22:23

When I use substr() I get a strange character at the end

$articleText = substr($articleText,0,500);

I have an output of 500 c

7条回答
  •  清酒与你
    2020-12-29 22:41

    use this function, It worked for me

    function substr_unicode($str, $s, $l = null) {
        return join("", array_slice(
            preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY), $s, $l));
    }
    

    Credits: http://php.net/manual/en/function.mb-substr.php#107698

提交回复
热议问题