php str_contains 怎么用
PHP的str_contains函数用于检查字符串中是否包含指定的子字符串。以下是使用str_contains函数的示例:
- 检查字符串是否包含指定的子字符串:
$string = "Hello, World!";
if (str_contains($string, "World")) {
echo "字符串包含'World'子字符串。";
} else {
echo "字符串不包含'World'子字符串。";
}
输出:
字符串包含'World'子字符串。
- 检查字符串是否以指定的子字符串开头:
$string = "Hello, World!";
if (str_starts_with($string, "Hello")) {
echo "字符串以'Hello'子字符串开头。";
} else {
echo "字符串不以'Hello'子字符串开头。";
}
输出:
字符串以'Hello'子字符串开头。
- 检查字符串是否以指定的子字符串结尾:
$string = "Hello, World!";
if (str_ends_with($string, "World!")) {
echo "字符串以'World!'子字符串结尾。";
} else {
echo "字符串不以'World!'子字符串结尾。";
}
输出:
字符串以'World!'子字符串结尾。
原文地址: http://www.cveoy.top/t/topic/LIY 著作权归作者所有。请勿转载和采集!