溫馨提示×

如何利用php的contains函數進行字符串匹配

PHP
小樊
104
2024-08-15 01:41:35
欄目: 編程語言

在PHP中,沒有一個名為contains的函數用于字符串匹配。不過,可以使用strpos函數來檢查一個字符串是否包含另一個字符串。以下是一個示例代碼:

$string1 = "Hello, world!";
$string2 = "world";

if (strpos($string1, $string2) !== false) {
    echo "The string contains 'world'";
} else {
    echo "The string does not contain 'world'";
}

在上面的代碼中,strpos函數返回第一個字符串在第二個字符串中的位置,如果找不到,則返回false。我們可以根據返回值來判斷一個字符串是否包含另一個字符串。

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