strlen(string $string): int
substr(string $str, int $start, int $length): string
mb_substr(string $str, int $start, int $length, string $encoding): string
strcmp(string $str1, string $str2): int // 区分大小写
strcasecmp(string $str1, string $str2): int //不区分大小写
strnatcmp(string $str1, string $str2): int //区分大小写
strnatcasecmp(string $str1, string $str2): int //不区分大小写
自然排序法比较的是字符串的数字部分,将字符串中的数字按照大小进行排序。
strncmp(string $str1, string $str2, int $len): int
比较字符串中的前n($len)个字符
返回值 | 说明 |
---|---|
0 | 字符串相等 |
1 | str1>str2 |
-1 | str1<str2 |
用来获取一个指定字符串在另一个字符串中首次出现的位置到后者末尾的子字符串。如果执行成功,则返回剩余字符串(存在相匹配的字符),否则返回 false。
strstr(string $haystack, mixed $needle [, bool $before_needle]): string // 区分大小写
stristr(string $haystack, mixed $needle [, bool $before_needle]): string // 不区分大小写
strrchr(string $haystack, mixed $needle): string // 区分大小写
substr_count(string $haystack, string $needle): int
str_replace(mixed $search, mixed $replace, mixed $subject, int $count): mixed // 区分大小写
str_ireplace(mixed $search, mixed $replace, mixed $subject, int $count): mixed // 不区分大小写
参数 | 说明 |
---|---|
mixed $search | 要查找的字符串 |
mixed $replace | 指定替换的值 |
mixed $subject | 指定查找范围 |
int $count | 获取执行替换的数量 |
substr_replace(mixed $string, mixed $replacement, mixed $start, mixed $length): mixed
参数 | 说明 |
---|---|
mixed $string | 要操作的原始字符串 |
mixed $replacement | 要替换后的新字符串 |
mixed $start | 要替换字符串开始的位置 |
mixed $length | 指定返回的字符串长度 正数:表示从开头覆盖 负数:表示从结尾保留 0:表示“插入”而非“替代” |
trim(string $str): string
ltrim(string $str, string $character_mask): string
rtrim(string $str, string $character_mask): string
explode(string $delimiter, string $string): array
参数 | 说明 |
---|---|
$delimiter | 分割符 |
$string | 要被分割的字符串 |
strtok(string $str, string $token): string
strtok(string $token): string
第一次调用 strtok() 函数时使用了 $str 参数。在首次调用后,该函数仅需要 $token 参数
$first_token = strtok('some/thing', '/');
$second_token = strtok('/');
var_dump($first_token, $second_token);
运行结果:
string(4) "some" string(5) "thing"
implode(string $glue, array $pieces): string
参数 | 说明 |
---|---|
$glue | 指定分割符 |
$pieces | 要被合成的数组 |
原文:https://www.cnblogs.com/xzh0717/p/10661641.html