PHP

如何在php中使用contains方法

小樊
82
2024-08-15 01:32:36
栏目: 编程语言

在PHP中,可以使用strpos函数来检查一个字符串是否包含另一个字符串。例如:

$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.";
}

这段代码会检查$string中是否包含$search,如果包含则输出"The string contains the search term.“,否则输出"The string does not contain the search term.”。

0
看了该问题的人还看了