如何在php中使用contains方法

PHP
小樊
82
2024-08-15 01:32:36
欄目: 編程語言

在PHP中,可以使用strpos函數(shù)來檢查一個(gè)字符串是否包含另一個(gè)字符串。例如:

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

if (strpos($string, $search) !== false) {
    echo "The string contains the search term.";
} else {
    echo "The string does not contain the search term.";
}

這段代碼會(huì)檢查$string中是否包含$search,如果包含則輸出"The string contains the search term.“,否則輸出"The string does not contain the search term.”。

0