Home >Backend Development >PHP Tutorial > 字符串操作,该怎么解决

字符串操作,该怎么解决

WBOY
WBOYOriginal
2016-06-13 13:51:16709browse

字符串操作
有一个变量:$arr[0]
1,我要判断它的长度,既其中有几个字符,怎么做呢?
2,如果我要取它的左数两位,怎么做呢?

刚刚接触PHP,请大家教我

------解决方案--------------------
$n=strlen($arr[0]);
$m=substr($arr[0],0,2);
------解决方案--------------------

int strlen ( string string )
取得字符串的长度, strlen(你的字符串)

string substr ( string string, int start [, int length] )
substr(你的字符串,0,2);
------解决方案--------------------
$len=strlen($arr[0]);
$str=substr($arr[0],0,2);


------解决方案--------------------
还要注意字符串是否含有宽字符。
------解决方案--------------------
宽字符是unicode

Statement:
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