1.字符串分割函数str_split($str,length),$str是要切割的字符串,length是分割长度,不写则默认是1,如果是负数则返回false
1 $str='helloworld!'; 2 print_r(str_split($str,2)); 3 echo '<br>'; 4 print_r(str_split($str));
输出结果:
Array ( [0] => he [1] => ll [2] => ow [3] => or [4] => ld [5] => ! )
Array ( [0] => h [1] => e [2] => l [3] => l [4] => o [5] => w [6] => o [7] => r [8] => l [9] => d [10] => ! )
2.字符串反转函数strrev($str),将字符串倒序返回
$str='hello world'; echo strrev($str);
输出结果:dlrow olleh
3.chunk_split($str,length,$s),将str分割成length长度的子字符串,并在后面添加字符串s,最后连接起来返回新字符串
$str='language'; echo chunk_split($str,2,',');
输出结果:la,ng,ua,ge,
4.移除左侧字符函数ltrim($str,$s),从$str的左侧移除$s
$str='helloworld'; $s='hello'; echo ltrim($str,$s);
输出结果:world
5.字符串转换成大写函数strtoupper($str)和转换成小写函数strtolower($str)
$str='hello world'; $str1=strtoupper($str); echo $str1,'<br>'; $str2=strtolower($str1); echo $str2;
输出结果:
HELLO WORLD
hello world