PHP 8 中的 str_starts_with 和 str_ends_with 函数
在PHP8中添加了str_starts_with和str_ends_with函数来检查给定的字符串是否以另一个字符串开头或结尾。如果它以另一个字符串开头和结尾,则返回true,否则返回false。
例子
str_starts_with('hello haystack', 'hello'); //开始字符串找到“真”
str_starts_with('hello haystack', 'stack'); //ends string found 'True'str_starts_with('hello haystack', 'hay'); //开始字符串找到“假”
str_starts_with('hello haystack', 'hay'); //ends string found 'False'str_starts_with()PHP8中的函数
此函数检查给定的字符串是否以字符串针开头。如果找到第一个字符串,则返回true,否则返回false。
str_starts_with(string $haystack, string $needle): bool
示例:使用str_starts_with()函数。
输出
String starts with 'hello'
注意:如果在第二个字符串中找不到给定的第一个起始字符串,则返回false。
str_ends_with()PHP8中的函数
此函数检查给定的字符串是否以字符串针结尾。如果找到给定的字符串结尾,则返回true,否则返回false。
str_ends_with(string $haystack, string $needle):bool
示例:使用str_ends_with()函数
输出
String ends with 'stack'
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短