$str = "hello world";
$pos = strripos($str, "o");
echo $pos; // 输出7
$str = "Hello World";
$pos = strripos(strtolower($str), "o");
echo $pos; // 输出7
$str = "hello world";
$pos = strripos($str, "o");
if ($pos >= 0) {
echo "子字符串存在";
} else {
echo "子字符串不存在";
}
$str = "hello world";
$keywords = array("hello", "world");
foreach ($keywords as $keyword) {
$pos = strripos($str, $keyword);
if ($pos >= 0) {
echo "$keyword 存在";
} else {
echo "$keyword 不存在";
}
}
$str = "hello world";
$keywords = array("hello", "world");
$positions = [];
foreach ($keywords as $keyword) {
$pos = strripos($str, $keyword);
if ($pos >= 0) {
$positions[] = $pos;
}
}
print_r($positions);