最近评论
正在载入评论列表...
![]() |
![]() |
4.3 访问单个字符
Accessing Individual Characters
函数strlen( )返回字符串中的字符数,即字符长度:
$string = 'Hello, world';
$length = strlen($string); // $length为12
可以在字符串中使用字符串偏移量语法来定位单个字符:
$string = 'Hello';
for ($i=0; $i < strlen($string); $i++) {
printf("The %dth character is %s\n", $i, $string{$i});
}
The 0th character is H
The 1th character is e
The 2th character is l
The 3th character is l
The 4th character is o