Home > Backend Development > PHP Tutorial > PHP string splitting function mb_substr

PHP string splitting function mb_substr

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:08:47
Original
1128 people have browsed it

    There are many ways to process strings in PHP. Tonight we have selected a very representative and widely used function to explain. It is the character

characterstring splitting function: mb_substr( ), I hope everyone will recognizetrue learning and understand!

// mb_substr() has several parameters, usually 3 or 4 parameters. Let’s talk about the last parameter in particular, which is to set the encoding

// Let’s look at the different encodings through cases below , what is the huge difference in the result

$str = 'We all have a dream rventrc'; $str = mb_substr($str, 0,3); // Since no encoding is specified,
1 Chinese character is treated as 3 characters in length, it will output: '我' $str = mb_substr($str, 0,3,'utf8'); // Since
utf8 encoding is specified, one Chinese character is 1 character in length, so it will be output :'We all' $str = mb_substr($str, -4,2,'utf8'); // This means starting from the 4th
from the bottom of , intercepting 2 characters of length // It means starting from the subscript Starting from 2, intercept until the 5th character from the bottom (excluding the 5th from the bottom)
, so the result is: 'Everyone has a dream rv'

$str = mb_substr($str, 2, -5 ,'utf8');


Through tonight’s detailed analysis, I believe everyone has a clearer understanding of intercepting Chinese strings. In fact, it can be easily solved by setting the encoding,

If you think the article is helpful to you, you can feel free to

tip a little!

PHP string splitting function mb_substr
The above introduces the PHP string splitting function mb_substr, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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