溫馨提示×

php indexof函數的使用方法是什么

PHP
小億
248
2024-03-07 14:55:23
欄目: 編程語言

在 PHP 中,沒有內置的 indexof 函數。不過,可以使用 strpos() 函數來查找一個字符串在另一個字符串中第一次出現的位置。

strpos() 函數的使用方法如下所示:

$string = "Hello, world!";
$substring = "world";

$position = strpos($string, $substring);

if ($position !== false) {
    echo "The substring was found at position: " . $position;
} else {
    echo "The substring was not found";
}

上述代碼將輸出:The substring was found at position: 7。表示子字符串 “world” 在字符串 “Hello, world!” 中第一次出現的位置是第 7 個字符的位置。如果子字符串沒有在字符串中找到,則 strpos() 函數將返回 false。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女