Detailed explanation of PHP truncation function mb_substr()

WBOY
Release: 2016-07-25 09:12:28
Original
1446 people have browsed it

In php, the mb_substr() function is a function used to cut Chinese and English characters

The mb_substr() function is not supported by default in php. We need to find php.ini in the windows directory, search for mbstring.dll, find ;extension=php_mbstring.dll, and remove the previous; sign before we can use mb_substr () function.

Function: mb_substr( $str, $start, $length, $encoding )
$str, the string that needs to be truncated
$start, the beginning of truncation
$length, length (1 represents a Chinese character)
$encoding, encoding, I set it to utf-8

Example:

$str="I am a good person!";
echo mb_substr($str,0,4,'utf-8'); //Result: I am a
?>

$str="I am a good man";

echo mb_substr($str,0,4,'utf-8'); //Result: I am

?>

Similar functions: mb_strcut() function

$str="I am a good man";

echo mb_substr($str,0,4,'utf-8'); //Result: I am

?>

$str="I am a good person!";
echo mb_substr($str,0,4,'utf-8'); //Result: me
?>




source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template